diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6cd0d85..dd7b75f0 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - run: corepack enable @@ -21,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/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..705a2fdb --- /dev/null +++ b/example/playground/scripts/prepare.mjs @@ -0,0 +1,15 @@ +import { writeFileSync } from 'node:fs' +import { execSync } from 'node: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' }) diff --git a/package.json b/package.json index e75e48af..eeecf0e7 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.14.2", diff --git a/src/commands/build.ts b/src/commands/build.ts index b3cddff7..7403a422 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' @@ -74,7 +74,7 @@ export default defineCommand({ cjsBridge: true, }, externals: [ - /dist\/runtime\//, + /dist[\\/]runtime[\\/]/, '@nuxt/schema', '@nuxt/schema-nightly', '@nuxt/schema-edge', @@ -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(pathToFileURL(normalizedId).href.replace(entry.input, entry.outDir!)), filename(normalizedId))) if (distFile) { return { external: true, diff --git a/test/build.spec.ts b/test/build.spec.ts index 1f3ec783..7f1dc24c 100644 --- a/test/build.spec.ts +++ b/test/build.spec.ts @@ -130,7 +130,7 @@ describe('module builder', () => { // 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 () => {