Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update tap to 18 #20

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
- name: Update npm
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- name: Install dependencies
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
- name: Update npm
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
!/.gitignore
!/.npmrc
!/.prettierrc.json
!/.taprc
!/Dockerfile
!/bin/
!/CHANGELOG*
Expand Down
11 changes: 11 additions & 0 deletions .taprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# vim: set filetype=yaml :
disable-coverage: false
allow-empty-coverage: true
allow-incomplete-coverage: true
plugin:
- "@tapjs/sinon"
- "!@tapjs/intercept"
- "@tapjs/tsx"
- "!@tapjs/typescript"
color: true
reporter: base
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

## Configuration & Usage

**Important Note** on '@tsconfig/node18/tsconfig.json' not found, and Tap:

There is currently an [issue](https://github.com/tapjs/tapjs/issues/976) in ts-node that causes a loading problem when combined with Tap.js. There is a [recommended](https://github.com/tapjs/tapjs/issues/976#issuecomment-1824784507) workaround for this. Once you update your skeleton, swap out these plugins:

```
npx tap plugin add @tapjs/tsx
npx tap plugin rm @tapjs/typescript
```


### CI
In your projects `package.json` you can set custom CI variables to extend the default workflow. The following configuration will add a Postgres service to the test job, as well as inject the `DOTENV_KEY` environment variables for dotenv vault usage.

Expand Down
4 changes: 2 additions & 2 deletions lib/content/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
- name: Update npm
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- name: Install dependencies
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
- name: Update npm
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion lib/content/clean.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ts-node
#!/usr/bin/env tsx
// This file is managed by code-skeleton. Do not make changes.

import { rmSync } from "node:fs";
Expand Down
1 change: 1 addition & 0 deletions lib/content/gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
!/.gitignore
!/.npmrc
!/.prettierrc.json
!/.taprc
!/Dockerfile
!/bin/
!/CHANGELOG*
Expand Down
4 changes: 2 additions & 2 deletions lib/content/update-shebang.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env ts-node
#!/usr/bin/env tsx

import { spawnSync } from "node:child_process";
import { readFile, writeFile } from "node:fs/promises";
import { dirname, resolve } from "node:path";

const ROOT = dirname(__dirname);
const tsShebang = "#!/usr/bin/env ts-node";
const tsShebang = "#!/usr/bin/env tsx";
const jsShebang = "#!/usr/bin/env node";

async function updateShebang (path: string) {
Expand Down
27 changes: 17 additions & 10 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,35 @@ export default async function (root: string, variables: Variables) {
prepack: "tsc --project tsconfig.build.json",
}
),
},
tap: {
coverage: true,
ts: true,
postinstall: "tap build",
},
types: "lib/index.d.ts",
devDependencies: {
"@tsconfig/node18": "^18.0.0",
"@types/node": "^18.0.0",
"@types/tap": "^15.0.0",
"@tsconfig/node20": "^20.0.0",
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.0.0",
"tap": "^16.0.0",
"ts-node": "^10.0.0",
"tap": "^18.7.0",
"tsx": "4.2.1",
"typescript": "^5.0.0"
},
"overrides": {
// Needed with the 4.2.1 tsx version lock to fix code coverage
// https://github.com/privatenumber/tsx/issues/433
"@tapjs/tsx": {
"tsx": "$tsx"
}
},
removeDependencies: [
"@types/tap",
"@tsconfig/node18"
]
}),
"tsconfig.json": json({
set: {
"//": "This file is partially managed by code-skeleton. Changes may be overwritten.",
extends: "@tsconfig/node18/tsconfig.json",
extends: "@tsconfig/node20/tsconfig.json",
},
append: {
include: [
Expand Down
30 changes: 17 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@code4rena/skeleton",
"version": "1.2.1",
"version": "2.0.0-2",
"description": "",
"main": "lib/index.js",
"scripts": {
Expand All @@ -13,7 +13,8 @@
"postlint": "npm run skeleton:verify",
"skeleton:apply": "code-skeleton apply",
"preskeleton:verify": "npm run prepack",
"skeleton:verify": "code-skeleton verify"
"skeleton:verify": "code-skeleton verify",
"postinstall": "tap build"
},
"keywords": [],
"author": "Nathan LaFreniere <[email protected]>",
Expand All @@ -22,20 +23,27 @@
"mustache": "^4.2.0"
},
"devDependencies": {
"@tsconfig/node18": "^18.0.0",
"@tapjs/sinon": "^1.1.18",
"@tapjs/tsx": "^1.1.19",
"@tsconfig/node20": "^20.0.0",
"@types/mustache": "^4.0.0",
"@types/node": "^18.0.0",
"@types/tap": "^15.0.0",
"@types/node": "^20.0.0",
"@types/sinon": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.0.0",
"tap": "^16.0.0",
"ts-node": "^10.0.0",
"typescript": "5.2.2"
"tap": "^18.7.0",
"tsx": "4.2.1",
"typescript": "^5.0.0"
},
"peerDependencies": {
"code-skeleton": "^2.0.0"
},
"overrides": {
"@tapjs/tsx": {
"tsx": "$tsx"
}
},
"skeleton": {
"module": ".",
"variables": {
Expand All @@ -54,9 +62,5 @@
"lib/**/*.d.ts",
"!lib/types/**",
"lib/content/**"
],
"tap": {
"coverage": true,
"ts": true
}
]
}
2 changes: 1 addition & 1 deletion scripts/clean.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ts-node
#!/usr/bin/env tsx
// This file is managed by code-skeleton. Do not make changes.

import { rmSync } from "node:fs";
Expand Down
4 changes: 2 additions & 2 deletions scripts/update-shebang.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env ts-node
#!/usr/bin/env tsx

import { spawnSync } from "node:child_process";
import { readFile, writeFile } from "node:fs/promises";
import { dirname, resolve } from "node:path";

const ROOT = dirname(__dirname);
const tsShebang = "#!/usr/bin/env ts-node";
const tsShebang = "#!/usr/bin/env tsx";
const jsShebang = "#!/usr/bin/env node";

async function updateShebang (path: string) {
Expand Down
6 changes: 0 additions & 6 deletions test/index.test.ts

This file was deleted.

91 changes: 91 additions & 0 deletions test/mustache.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import t from "tap";
import { mustache } from "../lib/mustache";

void t.test("mustache", async (t) => {
await t.test("must include a path", (t) => {
// @ts-expect-error bad data on purpose
t.throws(() => mustache({}));
t.end();
});

await t.test("should generate", async (t) => {
const { mustache } = t.mockRequire<typeof import("../lib/mustache")>("../lib/mustache", {
"node:fs/promises": {
readFile: (path: string) => {
t.equal(path, "path/to/file.txt");
return Promise.resolve("<% title %>");
}
}
});
const variables = {
title: "it generates"
};

const generator = mustache({
path: "path/to/file.txt",
variables,
});

const output = await generator.generate();
t.equal(output, "it generates");
});

await t.test("should validate partials", async (t) => {
const { mustache } = t.mockRequire<typeof import("../lib/mustache")>("../lib/mustache", {
"node:fs/promises": {
readFile: () => Promise.resolve("<% title %>")
}
});
const variables = {
title: "it generates"
};

const generator = mustache({
path: "path/to/file.txt",
variables,
});

const generateSpy = t.sinon.spy(generator, "generate");
const reportSpy = t.sinon.spy(generator, "report");

await generator.validate({
path: "path/to/file.txt",
found: "it generates\nand handles extras"
});

t.equal(generateSpy.callCount, 1);
// Report not called because we passed
t.equal(reportSpy.callCount, 0);
});

await t.test("should fail validation when base template not found", async (t) => {
const { mustache } = t.mockRequire<typeof import("../lib/mustache")>("../lib/mustache", {
"node:fs/promises": {
readFile: () => Promise.resolve("<% title %>")
}
});
const variables = {
title: "it generates"
};

const generator = mustache({
path: "path/to/file.txt",
variables,
});

const generateSpy = t.sinon.spy(generator, "generate");
const reportSpy = t.sinon.spy(generator, "report");

await generator.validate({
path: "path/to/file.txt",
found: "a new file"
});

t.equal(generateSpy.callCount, 1);
t.ok(reportSpy.calledOnceWithExactly({
expected: "it generates",
found: "a new file",
message: "path/to/file.txt does not include the original template"
}));
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"extends": "@tsconfig/node20/tsconfig.json",
"include": [
"**/*.ts",
".eslintrc.js"
Expand Down
Loading