From 93686193eccf0cb71646c0953f99741be2409a30 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 14 Oct 2024 10:49:22 +0100 Subject: [PATCH 01/10] ci: run test suite on windows --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bbcde64..2fa290e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,10 @@ on: jobs: ci: - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4 - run: corepack enable From d40ae0d354ed702a7a449cefb4c00aa1f8c8b2c2 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 14 Oct 2024 10:59:39 +0100 Subject: [PATCH 02/10] chore: get coverage in `test` command --- .github/workflows/ci.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fa290e4..41676709 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - run: pnpm install - run: pnpm dev:prepare - run: pnpm lint - - run: pnpm test -- --coverage + - run: pnpm test - run: pnpm build - run: pnpm example:build - run: pnpm test:types diff --git a/package.json b/package.json index cb4a48e3..508e2121 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts", "prepack": "pnpm build", "release": "pnpm vitest run && pnpm build && changelogen --release && pnpm publish && git push --follow-tags", - "test": "pnpm vitest", + "test": "pnpm vitest --coverage", "test:types": "vue-tsc --noEmit && pnpm -r test:types" }, "packageManager": "pnpm@9.12.1", From 4fc1a6b4686573b35091ce4ba907db5744a5a373 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 14 Oct 2024 11:13:01 +0100 Subject: [PATCH 03/10] chore: add logging --- test/build.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/build.spec.ts b/test/build.spec.ts index 1f3ec783..45dc7030 100644 --- a/test/build.spec.ts +++ b/test/build.spec.ts @@ -124,13 +124,14 @@ describe('module builder', () => { it('should correctly add extensions to imports from runtime/ directory', async () => { const moduleDts = await readFile(join(distDir, 'module.d.ts'), 'utf-8') const runtimeImport = findStaticImports(moduleDts).find(i => i.specifier.includes('runtime')) + console.log({ moduleDts, staticImports: findStaticImports(moduleDts) }) expect(runtimeImport!.code.trim()).toMatchInlineSnapshot(`"import { SharedTypeFromRuntime } from '../dist/runtime/plugins/plugin.js';"`) }) // TODO: https://github.com/nuxt/module-builder/issues/239 it('should generate components correctly', async () => { const componentFile = await readFile(join(distDir, 'runtime/components/TestMe.vue'), 'utf-8') - expect(componentFile).toMatchFileSnapshot('__snapshots__/TestMe.vue') + expect(componentFile.replace(/\r\n/g, '\n')).toMatchFileSnapshot('__snapshots__/TestMe.vue') }) it('should generate wrapped composables', async () => { From 5263dae47468f4de36f48e409a7d2d5179c5f040 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 14 Oct 2024 11:16:55 +0100 Subject: [PATCH 04/10] fix: use windows compatible external regexp --- src/commands/build.ts | 2 +- test/build.spec.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commands/build.ts b/src/commands/build.ts index b3cddff7..16664eea 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -74,7 +74,7 @@ export default defineCommand({ cjsBridge: true, }, externals: [ - /dist\/runtime\//, + /dist[\\/]runtime[\\/]/, '@nuxt/schema', '@nuxt/schema-nightly', '@nuxt/schema-edge', diff --git a/test/build.spec.ts b/test/build.spec.ts index 45dc7030..7f1dc24c 100644 --- a/test/build.spec.ts +++ b/test/build.spec.ts @@ -124,7 +124,6 @@ describe('module builder', () => { it('should correctly add extensions to imports from runtime/ directory', async () => { const moduleDts = await readFile(join(distDir, 'module.d.ts'), 'utf-8') const runtimeImport = findStaticImports(moduleDts).find(i => i.specifier.includes('runtime')) - console.log({ moduleDts, staticImports: findStaticImports(moduleDts) }) expect(runtimeImport!.code.trim()).toMatchInlineSnapshot(`"import { SharedTypeFromRuntime } from '../dist/runtime/plugins/plugin.js';"`) }) From 97fd7073e653af8ff2c74b78446ab3554c056137 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 14 Oct 2024 11:20:28 +0100 Subject: [PATCH 05/10] chore: add back log --- test/build.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/build.spec.ts b/test/build.spec.ts index 7f1dc24c..45dc7030 100644 --- a/test/build.spec.ts +++ b/test/build.spec.ts @@ -124,6 +124,7 @@ describe('module builder', () => { it('should correctly add extensions to imports from runtime/ directory', async () => { const moduleDts = await readFile(join(distDir, 'module.d.ts'), 'utf-8') const runtimeImport = findStaticImports(moduleDts).find(i => i.specifier.includes('runtime')) + console.log({ moduleDts, staticImports: findStaticImports(moduleDts) }) expect(runtimeImport!.code.trim()).toMatchInlineSnapshot(`"import { SharedTypeFromRuntime } from '../dist/runtime/plugins/plugin.js';"`) }) From 786badf6cf10409580ca27ce9c9a9f64886b2315 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 14 Oct 2024 12:12:47 +0100 Subject: [PATCH 06/10] fix: normalise runtime id --- src/commands/build.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/commands/build.ts b/src/commands/build.ts index 16664eea..f177d900 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -1,6 +1,6 @@ import { existsSync, promises as fsp } from 'node:fs' import { pathToFileURL } from 'node:url' -import { basename, dirname, join, resolve } from 'pathe' +import { basename, dirname, join, normalize, resolve } from 'pathe' import { filename } from 'pathe/utils' import { readPackageJSON } from 'pkg-types' import { parse } from 'tsconfck' @@ -102,7 +102,7 @@ export default defineCommand({ const runtimeEntries = ctx.options.entries.filter(entry => entry.builder === 'mkdist') const runtimeDirs = runtimeEntries.map(entry => basename(entry.input)) - const RUNTIME_RE = createRegExp(anyOf(...runtimeDirs).and('/')) + const RUNTIME_RE = createRegExp(anyOf(...runtimeDirs).and(anyOf('/', '\\'))) // Add extension for imports of runtime files in build options.plugins.unshift({ @@ -115,11 +115,12 @@ export default defineCommand({ if (!resolved) return + const normalizedId = normalize(resolved.id) for (const entry of runtimeEntries) { - if (!resolved.id.includes(entry.input)) + if (!normalizedId.includes(entry.input)) continue - const distFile = await resolvePath(join(dirname(resolved.id.replace(entry.input, entry.outDir!)), filename(resolved.id))) + const distFile = await resolvePath(join(dirname(normalizedId.replace(entry.input, entry.outDir!)), filename(normalizedId))) if (distFile) { return { external: true, From 43fcac6df3af020e44c6bfe14fb542d0c2552749 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 6 Dec 2024 12:29:44 +0000 Subject: [PATCH 07/10] fix: pass url to `resolvePath` --- src/commands/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/build.ts b/src/commands/build.ts index f177d900..7403a422 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -120,7 +120,7 @@ export default defineCommand({ if (!normalizedId.includes(entry.input)) continue - const distFile = await resolvePath(join(dirname(normalizedId.replace(entry.input, entry.outDir!)), filename(normalizedId))) + const distFile = await resolvePath(join(dirname(pathToFileURL(normalizedId).href.replace(entry.input, entry.outDir!)), filename(normalizedId))) if (distFile) { return { external: true, From 6d31dfb4509656222a465a14d6cb67b2dcb857b7 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 6 Dec 2024 12:53:32 +0000 Subject: [PATCH 08/10] chore: use script for type testing --- example/playground/package.json | 4 ++-- example/playground/scripts/prepare.mjs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 example/playground/scripts/prepare.mjs diff --git a/example/playground/package.json b/example/playground/package.json index 3f4e4de9..09065bfc 100644 --- a/example/playground/package.json +++ b/example/playground/package.json @@ -3,8 +3,8 @@ "name": "my-module-playground", "scripts": { "test:types": "pnpm test:types:bundler && pnpm test:types:node10", - "test:types:bundler": "echo typescript.tsConfig.compilerOptions.moduleResolution=bundler > .nuxtrc && nuxt prepare && vue-tsc --noEmit", - "test:types:node10": "echo typescript.tsConfig.compilerOptions.moduleResolution=node10 > .nuxtrc && nuxt prepare && vue-tsc --noEmit" + "test:types:bundler": "MODULE_RESOLUTION=bundler node scripts/prepare.mjs", + "test:types:node10": "MODULE_RESOLUTION=node10 node scripts/prepare.mjs" }, "dependencies": { "my-module": "workspace:*", diff --git a/example/playground/scripts/prepare.mjs b/example/playground/scripts/prepare.mjs new file mode 100644 index 00000000..3eb1ff18 --- /dev/null +++ b/example/playground/scripts/prepare.mjs @@ -0,0 +1,15 @@ +import { writeFileSync } from 'fs' +import { execSync } from 'child_process' + +const MODULE_RESOLUTION = process.env.MODULE_RESOLUTION + +if (!MODULE_RESOLUTION) { + throw new Error('MODULE_RESOLUTION should be defined') +} + +// Write the .nuxtrc file +writeFileSync('.nuxtrc', `typescript.tsConfig.compilerOptions.moduleResolution=${MODULE_RESOLUTION}\n`) + +// Run the commands +execSync('nuxt prepare', { stdio: 'inherit' }) +execSync('vue-tsc --noEmit', { stdio: 'inherit' }) \ No newline at end of file From 526ac87f648036e06fe180eed8b7b728d187a858 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 6 Dec 2024 13:17:36 +0000 Subject: [PATCH 09/10] chore: lint --- example/playground/scripts/prepare.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/playground/scripts/prepare.mjs b/example/playground/scripts/prepare.mjs index 3eb1ff18..705a2fdb 100644 --- a/example/playground/scripts/prepare.mjs +++ b/example/playground/scripts/prepare.mjs @@ -1,5 +1,5 @@ -import { writeFileSync } from 'fs' -import { execSync } from 'child_process' +import { writeFileSync } from 'node:fs' +import { execSync } from 'node:child_process' const MODULE_RESOLUTION = process.env.MODULE_RESOLUTION @@ -12,4 +12,4 @@ writeFileSync('.nuxtrc', `typescript.tsConfig.compilerOptions.moduleResolution=$ // Run the commands execSync('nuxt prepare', { stdio: 'inherit' }) -execSync('vue-tsc --noEmit', { stdio: 'inherit' }) \ No newline at end of file +execSync('vue-tsc --noEmit', { stdio: 'inherit' }) From d1a7f3e4e8d2a482292bdb06896f109f4ca86494 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 6 Dec 2024 13:17:52 +0000 Subject: [PATCH 10/10] chore: remove log --- test/build.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/build.spec.ts b/test/build.spec.ts index 45dc7030..7f1dc24c 100644 --- a/test/build.spec.ts +++ b/test/build.spec.ts @@ -124,7 +124,6 @@ describe('module builder', () => { it('should correctly add extensions to imports from runtime/ directory', async () => { const moduleDts = await readFile(join(distDir, 'module.d.ts'), 'utf-8') const runtimeImport = findStaticImports(moduleDts).find(i => i.specifier.includes('runtime')) - console.log({ moduleDts, staticImports: findStaticImports(moduleDts) }) expect(runtimeImport!.code.trim()).toMatchInlineSnapshot(`"import { SharedTypeFromRuntime } from '../dist/runtime/plugins/plugin.js';"`) })