Skip to content
Open
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
4 changes: 0 additions & 4 deletions packages/nuxt/build.config.ts

This file was deleted.

19 changes: 0 additions & 19 deletions packages/nuxt/generate-build-stubs.bash

This file was deleted.

3 changes: 1 addition & 2 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"local-pkg": "^1.1.2"
},
"devDependencies": {
"@nuxt/module-builder": "^0.8.4",
"@nuxt/nitro-server": "^3.21.6",
"nitro": "^3.0.260311-beta",
"nuxi": "^3.25.1",
Expand All @@ -76,7 +75,7 @@
"scripts": {
"build": "run-s build:types build:transpile",
"build:dev": "yarn build",
"build:nuxt-module": "bash ./generate-build-stubs.bash && nuxt-module-build build --outDir build/module",
"build:nuxt-module": "rollup -c rollup.module.config.mjs && tsc -p tsconfig.module.json && node scripts/build-module-meta.mjs",
"build:transpile": "rollup -c rollup.npm.config.mjs && yarn build:nuxt-module",
"build:types": "tsc -p tsconfig.types.json",
"build:watch": "run-p build:transpile:watch",
Expand Down
56 changes: 56 additions & 0 deletions packages/nuxt/rollup.module.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { readdirSync } from 'node:fs';
import { join } from 'node:path';
import esbuild from 'rollup-plugin-esbuild';

// The Nuxt module ships two kinds of output that live side by side in `build/module`:
// - `module.mjs`: the module entry, bundled from `src/module.ts`.
// - `runtime/**`: the files Nuxt injects into the consuming app, emitted one-to-one
// (never bundled) because the app's own build re-processes them.
// This config replaces `@nuxt/module-builder` so the package builds with plain rollup + tsc
// and doesn't couple us to a build tool that consumes the TypeScript compiler API.

// Anything that isn't a relative path is provided by the consuming app or Node at runtime
// (this covers `@sentry/*`, `nuxt/app`, `#imports`, node builtins), so it stays external.
const isExternal = id => !id.startsWith('.') && !id.startsWith('/') && !id.startsWith('\0');

const transpile = esbuild({
target: 'es2020',
// Don't read a per-package tsconfig; pin only what affects codegen.
tsconfig: false,
tsconfigRaw: { compilerOptions: { useDefineForClassFields: false } },
sourceMap: false,
});

function runtimeEntrypoints(dir = 'src/runtime', acc = []) {
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const full = join(dir, entry.name);
if (entry.isDirectory()) {
runtimeEntrypoints(full, acc);
} else if (entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts')) {
acc.push(full);
}
}

return acc;
}

export default [
{
input: 'src/module.ts',
output: { file: 'build/module/module.mjs', format: 'esm' },
external: isExternal,
plugins: [transpile],
},
{
input: runtimeEntrypoints(),
output: {
dir: 'build/module/runtime',
format: 'esm',
preserveModules: true,
preserveModulesRoot: 'src/runtime',
entryFileNames: '[name].js',
},
external: isExternal,
plugins: [transpile],
},
];
39 changes: 39 additions & 0 deletions packages/nuxt/scripts/build-module-meta.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';

// Emits the three non-compiled artifacts a Nuxt module needs alongside `module.mjs`,
// replacing what `@nuxt/module-builder` used to generate:
// - `module.cjs`: a CJS shim. It can't statically require the ESM-only `@nuxt/kit`,
// so it lazily imports the ESM entry instead.
// - `module.json`: module metadata Nuxt reads. Keep the `meta` fields in sync with
// `defineNuxtModule({ meta })` in `src/module.ts`.
// - `types.d.ts`: the type entry referenced by the `./module` export.

const outDir = 'build/module';
const { version } = JSON.parse(readFileSync('package.json', 'utf-8'));

writeFileSync(
join(outDir, 'module.cjs'),
`module.exports = function(...args) {
return import('./module.mjs').then(m => m.default.call(this, ...args))
}
const _meta = module.exports.meta = require('./module.json')
module.exports.getMeta = () => Promise.resolve(_meta)
`,
);

writeFileSync(
join(outDir, 'module.json'),
`${JSON.stringify(
{
name: '@sentry/nuxt/module',
configKey: 'sentry',
compatibility: { nuxt: '>=3.7.0' },
version,
},
null,
2,
)}\n`,
);

writeFileSync(join(outDir, 'types.d.ts'), "export { type ModuleOptions, default } from './module'\n");
2 changes: 1 addition & 1 deletion packages/nuxt/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.json",

"include": ["src/**/*", "build.config.ts"],
"include": ["src/**/*"],

"compilerOptions": {
// package-specific options
Expand Down
11 changes: 11 additions & 0 deletions packages/nuxt/tsconfig.module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"include": ["src/module.ts", "src/runtime/**/*"],
"compilerOptions": {
"declaration": true,
"declarationMap": false,
"emitDeclarationOnly": true,
"outDir": "build/module",
"rootDir": "src"
}
}
1 change: 0 additions & 1 deletion packages/nuxt/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": ["build.config.ts"],
"compilerOptions": {
"declaration": true,
"declarationMap": true,
Expand Down
Loading
Loading