Skip to content

Commit

Permalink
fix(nuxt): Add nuxt-module-builder for build output (#13183)
Browse files Browse the repository at this point in the history
Reverting the change in this PR:
#13138
For the time being (until this is debugged and fixed), this change is
reverted and the Nuxt module will still be built with the
nuxt-module-builder.

The changed build-setup led to an error in `nuxt dev` and the navigation
in the E2E test apps did not work. The error message:
```
ERROR  [worker reload] [worker init] Package import specifier "#internal/nitro/virtual/app-config" is not defined in package /Users/sigridh/Documents/DEV/sentry-javascript-examples/node_modules/nitropack/package.json imported from /Users/sigridh/Documents/DEV/sentry-javascript-examples/node_modules/nitropack/dist/runtime/config.mjs
```

Similar errors were reported here:

- nuxt/content#2736
- nuxt/icon#204
- nuxt/nuxt#13801
  • Loading branch information
s1gr1d committed Aug 2, 2024
1 parent 6a61244 commit 988d8e7
Show file tree
Hide file tree
Showing 9 changed files with 409 additions and 46 deletions.
13 changes: 7 additions & 6 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
}
},
"./module": {
"types": "./build/types/module/index.d.ts",
"import": "./build/esm/module/index.js",
"require": "./build/cjs/module/index.js"
"types": "./build/module/types.d.ts",
"import": "./build/module/module.mjs",
"require": "./build/module/module.cjs"
}
},
"publishConfig": {
Expand All @@ -53,12 +53,14 @@
"@sentry/vue": "8.22.0"
},
"devDependencies": {
"@nuxt/module-builder": "0.8.1",
"nuxt": "^3.12.2"
},
"scripts": {
"build": "run-s build:types build:transpile",
"build:dev": "yarn build",
"build:transpile": "rollup -c rollup.npm.config.mjs",
"build:nuxt-module": "nuxt-module-build build --outDir build/module",
"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 build:types:watch",
"build:dev:watch": "yarn build:watch",
Expand Down Expand Up @@ -88,8 +90,7 @@
"outputs": [
"{projectRoot}/build/cjs",
"{projectRoot}/build/esm",
"{projectRoot}/build/cjs/module",
"{projectRoot}/build/esm/module"
"{projectRoot}/build/module"
]
}
}
Expand Down
13 changes: 6 additions & 7 deletions packages/nuxt/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@ export default [
'src/index.client.ts',
'src/client/index.ts',
'src/server/index.ts',
'src/module/index.ts',
'src/module.ts',
],
packageSpecificConfig: {
external: ['nuxt/app'],
},
}),
),
/* The Nuxt module plugins are also built with the @nuxt/module-builder.
This rollup setup is still left here for an easier switch between the setups while
manually testing different built outputs (module-builder vs. rollup only) */
...makeNPMConfigVariants(
makeBaseNPMConfig({
entrypoints: ['src/module/plugins/sentry.client.ts', 'src/module/plugins/sentry.server.ts'],
entrypoints: ['src/runtime/plugins/sentry.client.ts', 'src/runtime/plugins/sentry.server.ts'],

packageSpecificConfig: {
external: ['nuxt/app', 'nitropack/runtime', 'h3'],
output: {
// Preserve the original file structure (i.e., so that everything is still relative to `src`)
entryFileNames: 'module/[name].js',
entryFileNames: 'runtime/[name].js',
},
},
}),
),
];

/*
*/
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as fs from 'fs';
import * as path from 'path';
import { addPlugin, addPluginTemplate, addServerPlugin, createResolver, defineNuxtModule } from '@nuxt/kit';
import type { SentryNuxtModuleOptions } from '../common/types';
import { setupSourceMaps } from '../vite/sourceMaps';
import type { SentryNuxtModuleOptions } from './common/types';
import { setupSourceMaps } from './vite/sourceMaps';

export type ModuleOptions = SentryNuxtModuleOptions;

Expand Down Expand Up @@ -31,7 +31,7 @@ export default defineNuxtModule<ModuleOptions>({
'export default defineNuxtPlugin(() => {})',
});

addPlugin({ src: moduleDirResolver.resolve('./plugins/sentry.client'), mode: 'client' });
addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'), mode: 'client' });
}

const serverConfigFile = findDefaultSdkInitFile('server');
Expand All @@ -46,7 +46,7 @@ export default defineNuxtModule<ModuleOptions>({
'export default defineNuxtPlugin(() => {})',
});

addServerPlugin(moduleDirResolver.resolve('./plugins/sentry.server'));
addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));
}

if (clientConfigFile || serverConfigFile) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/nuxt/test/client/runtime/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { extractErrorContext } from '../../../src/module/utils';
import { extractErrorContext } from '../../../src/runtime/utils';

describe('extractErrorContext', () => {
it('returns empty object for undefined or empty context', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/test/server/runtime/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { addSentryTracingMetaTags } from '../../../src/module/utils';
import { addSentryTracingMetaTags } from '../../../src/runtime/utils';

const mockReturns = vi.hoisted(() => {
return {
Expand Down
417 changes: 390 additions & 27 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 988d8e7

Please sign in to comment.