Skip to content

Commit 8a9c494

Browse files
committed
always use esm version of templates
1 parent 0696794 commit 8a9c494

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

packages/nextjs/.eslintrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@ module.exports = {
1111
rules: {
1212
'@sentry-internal/sdk/no-async-await': 'off',
1313
},
14+
overrides: [
15+
{
16+
files: ['scripts/**/*.ts'],
17+
parserOptions: {
18+
project: ['../../tsconfig.dev.json'],
19+
},
20+
},
21+
],
1422
};

packages/nextjs/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
"scripts": {
4646
"build": "run-p build:rollup build:types",
4747
"build:dev": "run-s build",
48-
"build:rollup": "rollup -c rollup.npm.config.js",
48+
"build:rollup": "ts-node scripts/buildRollup.ts",
4949
"build:types": "tsc -p tsconfig.types.json",
5050
"build:watch": "run-p build:rollup:watch build:types:watch",
5151
"build:dev:watch": "run-s build:watch",
52-
"build:rollup:watch": "rollup -c rollup.npm.config.js --watch",
52+
"build:rollup:watch": "nodemon --ext ts --watch src scripts/buildRollup.ts",
5353
"build:types:watch": "tsc -p tsconfig.types.json --watch",
5454
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build",
5555
"circularDepCheck": "madge --circular src/index.client.ts && madge --circular --exclude 'config/types\\.ts' src/index.server.ts # see https://github.com/pahen/madge/issues/306",
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as childProcess from 'child_process';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
5+
/**
6+
* Run the given shell command, piping the shell process's `stdin`, `stdout`, and `stderr` to that of the current
7+
* process. Returns contents of `stdout`.
8+
*/
9+
function run(cmd: string, options?: childProcess.ExecSyncOptions): string | Buffer {
10+
return childProcess.execSync(cmd, { stdio: 'inherit', ...options });
11+
}
12+
13+
run('yarn rollup -c rollup.npm.config.js');
14+
15+
// Regardless of whether nextjs is using the CJS or ESM version of our SDK, we want the code from our templates to be in
16+
// ESM (since we'll be adding it onto page files which are themselves written in ESM), so copy the ESM versions of the
17+
// templates over into the CJS build directory. (Building only the ESM version and sticking it in both locations is
18+
// something which in theory Rollup could do, but it would mean refactoring our Rollup helper functions, which isn't
19+
// worth it just for this.)
20+
const cjsTemplateDir = 'build/cjs/config/templates/';
21+
const esmTemplateDir = 'build/esm/config/templates/';
22+
fs.readdirSync(esmTemplateDir).forEach(templateFile =>
23+
fs.copyFileSync(path.join(esmTemplateDir, templateFile), path.join(cjsTemplateDir, templateFile)),
24+
);

0 commit comments

Comments
 (0)