Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions example/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
15 changes: 15 additions & 0 deletions example/playground/scripts/prepare.mjs
Original file line number Diff line number Diff line change
@@ -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' })
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -74,7 +74,7 @@ export default defineCommand({
cjsBridge: true,
},
externals: [
/dist\/runtime\//,
/dist[\\/]runtime[\\/]/,
'@nuxt/schema',
'@nuxt/schema-nightly',
'@nuxt/schema-edge',
Expand Down Expand Up @@ -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({
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Loading