From 9436f4ca10944802e8c7bcedb4a8beb19014ebbf Mon Sep 17 00:00:00 2001 From: HazA Date: Tue, 26 Feb 2019 16:13:13 +0100 Subject: [PATCH] feat: Remove esm rewrite script, expose module --- .gitignore | 2 +- packages/browser/package.json | 5 ++-- packages/core/package.json | 5 ++-- packages/hub/package.json | 5 ++-- packages/minimal/package.json | 5 ++-- packages/node/package.json | 1 + packages/types/package.json | 5 ++-- packages/utils/package.json | 7 ++--- packages/utils/tsconfig.esm.json | 10 -------- scripts/esm-rewrite.js | 44 -------------------------------- 10 files changed, 14 insertions(+), 75 deletions(-) delete mode 100644 packages/utils/tsconfig.esm.json delete mode 100644 scripts/esm-rewrite.js diff --git a/.gitignore b/.gitignore index d4d81b35509e..300aee3c0cee 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ packages/*/package-lock.json # build and test build/ packages/*/dist/ -/packages/*/esm +packages/*/esm/ coverage/ scratch/ *.pyc diff --git a/packages/browser/package.json b/packages/browser/package.json index 2f0b34224ff3..057d9e710d90 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -10,6 +10,7 @@ "node": ">=6" }, "main": "dist/index.js", + "module": "esm/index.js", "types": "dist/index.d.ts", "publishConfig": { "access": "public" @@ -55,9 +56,7 @@ "scripts": { "build": "run-p build:esm build:es5", "build:es5": "rollup --config", - "build:esm": "run-s build:esm:transpile build:esm:rewrite", - "build:esm:transpile": "tsc -p tsconfig.esm.json", - "build:esm:rewrite": "node ../../scripts/esm-rewrite.js", + "build:esm": "tsc -p tsconfig.esm.json", "build:watch": "rollup --config --watch", "clean": "rimraf dist coverage .rpt2_cache build", "lint": "run-s lint:prettier lint:tslint", diff --git a/packages/core/package.json b/packages/core/package.json index 21fe26efef69..308920873fa5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -10,6 +10,7 @@ "node": ">=6" }, "main": "dist/index.js", + "module": "esm/index.js", "types": "dist/index.d.ts", "publishConfig": { "access": "public" @@ -33,9 +34,7 @@ "scripts": { "build": "run-p build:es5 build:esm", "build:es5": "tsc -p tsconfig.build.json", - "build:esm": "run-s build:esm:transpile build:esm:rewrite", - "build:esm:transpile": "tsc -p tsconfig.esm.json", - "build:esm:rewrite": "node ../../scripts/esm-rewrite.js", + "build:esm": "tsc -p tsconfig.esm.json", "build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput", "clean": "rimraf dist coverage", "lint": "run-s lint:prettier lint:tslint", diff --git a/packages/hub/package.json b/packages/hub/package.json index c51527a7aae2..56f6426aa1a9 100644 --- a/packages/hub/package.json +++ b/packages/hub/package.json @@ -10,6 +10,7 @@ "node": ">=6" }, "main": "dist/index.js", + "module": "esm/index.js", "types": "dist/index.d.ts", "publishConfig": { "access": "public" @@ -31,9 +32,7 @@ "scripts": { "build": "run-p build:es5 build:esm", "build:es5": "tsc -p tsconfig.build.json", - "build:esm": "run-s build:esm:transpile build:esm:rewrite", - "build:esm:transpile": "tsc -p tsconfig.esm.json", - "build:esm:rewrite": "node ../../scripts/esm-rewrite.js", + "build:esm": "tsc -p tsconfig.esm.json", "build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput", "clean": "rimraf dist coverage", "lint": "run-s lint:prettier lint:tslint", diff --git a/packages/minimal/package.json b/packages/minimal/package.json index 6991d00ecf3c..85c23d3a546f 100644 --- a/packages/minimal/package.json +++ b/packages/minimal/package.json @@ -10,6 +10,7 @@ "node": ">=6" }, "main": "dist/index.js", + "module": "esm/index.js", "types": "dist/index.d.ts", "publishConfig": { "access": "public" @@ -31,9 +32,7 @@ "scripts": { "build": "run-p build:es5 build:esm", "build:es5": "tsc -p tsconfig.build.json", - "build:esm": "run-s build:esm:transpile build:esm:rewrite", - "build:esm:transpile": "tsc -p tsconfig.esm.json", - "build:esm:rewrite": "node ../../scripts/esm-rewrite.js", + "build:esm": "tsc -p tsconfig.esm.json", "build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput", "clean": "rimraf dist coverage", "lint": "run-s lint:prettier lint:tslint", diff --git a/packages/node/package.json b/packages/node/package.json index 16ceda5d7263..1bcc7bd9496b 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -10,6 +10,7 @@ "node": ">=6" }, "main": "dist/index.js", + "module": "esm/index.js", "types": "dist/index.d.ts", "publishConfig": { "access": "public" diff --git a/packages/types/package.json b/packages/types/package.json index 1054f4e2b2f0..0cc63cdf5d29 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -10,6 +10,7 @@ "node": ">=6" }, "main": "dist/index.js", + "module": "esm/index.js", "types": "dist/index.d.ts", "publishConfig": { "access": "public" @@ -24,9 +25,7 @@ "scripts": { "build": "run-p build:es5 build:esm", "build:es5": "tsc -p tsconfig.build.json", - "build:esm": "run-s build:esm:transpile build:esm:rewrite", - "build:esm:transpile": "tsc -p tsconfig.esm.json", - "build:esm:rewrite": "node ../../scripts/esm-rewrite.js", + "build:esm": "tsc -p tsconfig.esm.json", "build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput", "lint": "run-s lint:prettier lint:tslint", "lint:prettier": "prettier-check \"{src,test}/**/*.ts\"", diff --git a/packages/utils/package.json b/packages/utils/package.json index 00a13b14e754..9ed46dcd7a2e 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -27,13 +27,10 @@ "typescript": "^3.3.3" }, "scripts": { - "build": "run-s clean && run-p build:es5 build:esm", + "build": "run-s clean && run-p build:es5", "build:es5": "tsc -p tsconfig.build.json", - "build:esm": "run-s build:esm:transpile build:esm:rewrite", - "build:esm:transpile": "tsc -p tsconfig.esm.json", - "build:esm:rewrite": "node ../../scripts/esm-rewrite.js", "build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput", - "clean": "rimraf dist coverage *.js *.js.map *.d.ts", + "clean": "rimraf dist esm coverage *.js *.js.map *.d.ts", "lint": "run-s lint:prettier lint:tslint", "lint:prettier": "prettier-check \"{src,test}/**/*.ts\"", "lint:tslint": "tslint -t stylish -p .", diff --git a/packages/utils/tsconfig.esm.json b/packages/utils/tsconfig.esm.json deleted file mode 100644 index 0c15034857ef..000000000000 --- a/packages/utils/tsconfig.esm.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.esm.json", - "compilerOptions": { - "baseUrl": ".", - "outDir": "esm", - "rootDir": "src" - }, - "exclude": [], - "include": ["src/**/*.ts"] -} diff --git a/scripts/esm-rewrite.js b/scripts/esm-rewrite.js deleted file mode 100644 index bd3c9192e478..000000000000 --- a/scripts/esm-rewrite.js +++ /dev/null @@ -1,44 +0,0 @@ -const { relative } = require('path'); -const replace = require('replace-in-file'); - -/** - * capture group 1 - * `import/export [...] from [...]` - */ -const inExport = '(import|export)'; -/** - * capture group 2 - * Either `import {x, y, z} from [...]`, `import xyz from [...]` or `import * as xyz from [...]` - */ -const thing = '({[a-zA-Z0-9,\\s]*}| *(\\* as )?[a-zA-Z] *)'; -/** - * capture group 4 - * packages with esm modules - */ -const esmPkgs = `(${['browser', 'core', 'hub', 'minimal', 'types', 'utils'].join('|')})`; -/** - * `from '@sentry/pkg/dist/xyz';` > `from '@sentry/pkg/xyz';` - */ -const removeDist = '(/dist)?'; -/** - * capture group 6 - * `from '@sentry/pkg/xyz';` > `from '@sentry/pkg/esm/xyz';`, if not already imported from esm - */ -const subPath = '(/(?!esm)[a-zA-Z0-9/]+)?'; - -const options = { - files: `${process.cwd()}/esm/**/*.{js,d.ts}`, - from: new RegExp(`${inExport} ${thing} from '@sentry/${esmPkgs}${removeDist}${subPath}';`, 'gm'), - to: "$1 $2 from '@sentry/$4/esm$6';", -}; - -const changes = replace.sync(options); - -if ('VERBOSE' in process.env) { - if (changes.length > 0) { - const esmDir = `${process.cwd()}/esm`; - console.log(`Imports rewritten to esm in:\n - ${changes.map(path => relative(esmDir, path)).join('\n - ')}`); - } else { - console.log('No imports rewritten'); - } -}