From 2d866c942190e4da8ab6e178b11514cd7d4fa667 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 11 Apr 2023 09:57:27 -0700 Subject: [PATCH] refactor: package reform BREAKING CHANGE --- .../aria-reflection/scripts/rollup.config.js | 41 ------- packages/@lwc/aria-reflection/tsconfig.json | 1 - .../scripts/rollup.config.js | 41 ------- .../@lwc/babel-plugin-component/tsconfig.json | 1 - ...abel-plugin-proposal-class-properties.d.ts | 0 ...el-plugin-proposal-object-rest-spread.d.ts | 0 packages/@lwc/compiler/tsconfig.json | 7 +- .../@lwc/engine-core/scripts/rollup.config.js | 50 -------- packages/@lwc/engine-core/tsconfig.json | 1 - .../{ => src}/typings/observedAttributes.d.ts | 0 packages/@lwc/engine-dom/tsconfig.json | 3 +- .../engine-server/scripts/rollup.config.js | 51 -------- packages/@lwc/engine-server/tsconfig.json | 1 - packages/@lwc/errors/tsconfig.json | 5 - .../features/scripts/rollup/rollup.config.js | 42 ------- .../features/src/__tests__/features.spec.ts | 2 +- .../src/__tests__/lwcRuntimeFlags.spec.ts | 2 +- .../src/__tests__/setFeatureFlag.spec.ts | 2 +- .../@lwc/features/src/{flags.ts => index.ts} | 0 packages/@lwc/features/tsconfig.json | 2 - packages/@lwc/module-resolver/tsconfig.json | 8 +- packages/@lwc/rollup-plugin/src/index.ts | 6 +- packages/@lwc/rollup-plugin/tsconfig.json | 5 - .../shared/scripts/rollup/rollup.config.js | 41 ------- packages/@lwc/shared/tsconfig.json | 4 - packages/@lwc/style-compiler/tsconfig.json | 5 - .../scripts/rollup/rollup.config.js | 58 --------- packages/@lwc/synthetic-shadow/tsconfig.json | 5 +- .../{ => src}/typings/parse5-internals.d.ts | 0 .../{ => src}/typings/parse5.d.ts | 0 .../{ => src}/typings/parse5errors.d.ts | 0 packages/@lwc/template-compiler/tsconfig.json | 7 +- .../scripts/rollup/rollup.config.js | 41 ------- packages/@lwc/wire-service/tsconfig.json | 1 - packages/lwc/scripts/utils/helpers.js | 2 +- .../rollup}/rollup.config.js | 75 ++++++++---- scripts/rollup/typescript.js | 23 ---- scripts/rollup/writeDistAndTypes.js | 26 ---- .../tasks/check-and-rewrite-package-json.js | 113 ++++++++++++++++++ tsconfig.json | 5 +- 40 files changed, 180 insertions(+), 497 deletions(-) delete mode 100644 packages/@lwc/aria-reflection/scripts/rollup.config.js delete mode 100644 packages/@lwc/babel-plugin-component/scripts/rollup.config.js rename packages/@lwc/compiler/{ => src}/typings/@babel-plugin-proposal-class-properties.d.ts (100%) rename packages/@lwc/compiler/{ => src}/typings/@babel-plugin-proposal-object-rest-spread.d.ts (100%) delete mode 100644 packages/@lwc/engine-core/scripts/rollup.config.js rename packages/@lwc/engine-dom/{ => src}/typings/observedAttributes.d.ts (100%) delete mode 100644 packages/@lwc/engine-server/scripts/rollup.config.js delete mode 100644 packages/@lwc/features/scripts/rollup/rollup.config.js rename packages/@lwc/features/src/{flags.ts => index.ts} (100%) delete mode 100644 packages/@lwc/shared/scripts/rollup/rollup.config.js delete mode 100644 packages/@lwc/synthetic-shadow/scripts/rollup/rollup.config.js rename packages/@lwc/template-compiler/{ => src}/typings/parse5-internals.d.ts (100%) rename packages/@lwc/template-compiler/{ => src}/typings/parse5.d.ts (100%) rename packages/@lwc/template-compiler/{ => src}/typings/parse5errors.d.ts (100%) delete mode 100644 packages/@lwc/wire-service/scripts/rollup/rollup.config.js rename {packages/@lwc/engine-dom/scripts => scripts/rollup}/rollup.config.js (62%) delete mode 100644 scripts/rollup/typescript.js delete mode 100644 scripts/rollup/writeDistAndTypes.js create mode 100644 scripts/tasks/check-and-rewrite-package-json.js diff --git a/packages/@lwc/aria-reflection/scripts/rollup.config.js b/packages/@lwc/aria-reflection/scripts/rollup.config.js deleted file mode 100644 index 5b9e863bbc..0000000000 --- a/packages/@lwc/aria-reflection/scripts/rollup.config.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ - -/* eslint-env node */ - -const path = require('path'); -const typescript = require('../../../../scripts/rollup/typescript'); -const writeDistAndTypes = require('../../../../scripts/rollup/writeDistAndTypes'); -const { version, dependencies, peerDependencies } = require('../package.json'); -const banner = `/**\n * Copyright (C) 2018 salesforce.com, inc.\n */`; -const footer = `/** version: ${version} */`; - -const formats = ['es', 'cjs']; - -module.exports = { - input: path.resolve(__dirname, '../src/index.ts'), - - output: formats.map((format) => { - return { - file: `index${format === 'cjs' ? '.cjs' : ''}.js`, - sourcemap: true, - format, - banner, - footer, - }; - }), - - plugins: [typescript(), writeDistAndTypes()], - - onwarn({ code, message }) { - if (!process.env.ROLLUP_WATCH && code !== 'CIRCULAR_DEPENDENCY') { - throw new Error(message); - } - }, - - external: [...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {})], -}; diff --git a/packages/@lwc/aria-reflection/tsconfig.json b/packages/@lwc/aria-reflection/tsconfig.json index 170ece25f9..6fa56998a0 100644 --- a/packages/@lwc/aria-reflection/tsconfig.json +++ b/packages/@lwc/aria-reflection/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../../../tsconfig.json", "compilerOptions": { - "outDir": ".", "lib": ["dom", "es2018"] }, diff --git a/packages/@lwc/babel-plugin-component/scripts/rollup.config.js b/packages/@lwc/babel-plugin-component/scripts/rollup.config.js deleted file mode 100644 index 402601b6ec..0000000000 --- a/packages/@lwc/babel-plugin-component/scripts/rollup.config.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ - -/* eslint-env node */ - -const path = require('node:path'); -const typescript = require('../../../../scripts/rollup/typescript'); -const writeDistAndTypes = require('../../../../scripts/rollup/writeDistAndTypes'); -const { version, dependencies, peerDependencies } = require('../package.json'); -const banner = `/**\n * Copyright (C) 2023 salesforce.com, inc.\n */`; -const footer = `/** version: ${version} */`; - -const formats = ['es', 'cjs']; - -module.exports = { - input: path.resolve(__dirname, '../src/index.ts'), - - output: formats.map((format) => { - return { - file: `index${format === 'cjs' ? '.cjs' : ''}.js`, - sourcemap: true, - format, - banner, - footer, - }; - }), - - plugins: [typescript(), writeDistAndTypes()], - - onwarn({ code, message }) { - if (!process.env.ROLLUP_WATCH && code !== 'CIRCULAR_DEPENDENCY') { - throw new Error(message); - } - }, - - external: [...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {}), 'path'], -}; diff --git a/packages/@lwc/babel-plugin-component/tsconfig.json b/packages/@lwc/babel-plugin-component/tsconfig.json index 8c69972637..5f9e0a6df9 100644 --- a/packages/@lwc/babel-plugin-component/tsconfig.json +++ b/packages/@lwc/babel-plugin-component/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../../../tsconfig.json", "compilerOptions": { - "outDir": ".", "lib": ["es2018"] }, diff --git a/packages/@lwc/compiler/typings/@babel-plugin-proposal-class-properties.d.ts b/packages/@lwc/compiler/src/typings/@babel-plugin-proposal-class-properties.d.ts similarity index 100% rename from packages/@lwc/compiler/typings/@babel-plugin-proposal-class-properties.d.ts rename to packages/@lwc/compiler/src/typings/@babel-plugin-proposal-class-properties.d.ts diff --git a/packages/@lwc/compiler/typings/@babel-plugin-proposal-object-rest-spread.d.ts b/packages/@lwc/compiler/src/typings/@babel-plugin-proposal-object-rest-spread.d.ts similarity index 100% rename from packages/@lwc/compiler/typings/@babel-plugin-proposal-object-rest-spread.d.ts rename to packages/@lwc/compiler/src/typings/@babel-plugin-proposal-object-rest-spread.d.ts diff --git a/packages/@lwc/compiler/tsconfig.json b/packages/@lwc/compiler/tsconfig.json index b7c92ec45e..af627f6afe 100755 --- a/packages/@lwc/compiler/tsconfig.json +++ b/packages/@lwc/compiler/tsconfig.json @@ -1,10 +1,5 @@ { "extends": "../../../tsconfig.json", - "compilerOptions": { - "outDir": "dist/commonjs", - "declarationDir": "dist/types" - }, - - "include": ["src/", "typings/"] + "include": ["src/"] } diff --git a/packages/@lwc/engine-core/scripts/rollup.config.js b/packages/@lwc/engine-core/scripts/rollup.config.js deleted file mode 100644 index e25e3ac3be..0000000000 --- a/packages/@lwc/engine-core/scripts/rollup.config.js +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ - -/* eslint-env node */ - -const path = require('path'); - -const { nodeResolve } = require('@rollup/plugin-node-resolve'); -const typescript = require('../../../../scripts/rollup/typescript'); -const writeDistAndTypes = require('../../../../scripts/rollup/writeDistAndTypes'); - -const { version, dependencies, peerDependencies } = require('../package.json'); - -const banner = `/* proxy-compat-disable */`; -const footer = `/* version: ${version} */`; -const formats = ['es', 'cjs']; - -module.exports = { - input: path.resolve(__dirname, '../src/index.ts'), - - output: formats.map((format) => { - return { - file: `engine-core${format === 'cjs' ? '.cjs' : ''}.js`, - sourcemap: true, - format, - banner: banner, - footer: footer, - }; - }), - - plugins: [ - nodeResolve({ - resolveOnly: [/^@lwc\//, 'observable-membrane'], - }), - typescript(), - writeDistAndTypes(), - ], - - onwarn({ code, message }) { - if (!process.env.ROLLUP_WATCH && code !== 'CIRCULAR_DEPENDENCY') { - throw new Error(message); - } - }, - - external: [...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {})], -}; diff --git a/packages/@lwc/engine-core/tsconfig.json b/packages/@lwc/engine-core/tsconfig.json index 170ece25f9..6fa56998a0 100644 --- a/packages/@lwc/engine-core/tsconfig.json +++ b/packages/@lwc/engine-core/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../../../tsconfig.json", "compilerOptions": { - "outDir": ".", "lib": ["dom", "es2018"] }, diff --git a/packages/@lwc/engine-dom/typings/observedAttributes.d.ts b/packages/@lwc/engine-dom/src/typings/observedAttributes.d.ts similarity index 100% rename from packages/@lwc/engine-dom/typings/observedAttributes.d.ts rename to packages/@lwc/engine-dom/src/typings/observedAttributes.d.ts diff --git a/packages/@lwc/engine-dom/tsconfig.json b/packages/@lwc/engine-dom/tsconfig.json index 71a279e7a8..6fa56998a0 100644 --- a/packages/@lwc/engine-dom/tsconfig.json +++ b/packages/@lwc/engine-dom/tsconfig.json @@ -2,9 +2,8 @@ "extends": "../../../tsconfig.json", "compilerOptions": { - "outDir": ".", "lib": ["dom", "es2018"] }, - "include": ["src/", "typings/"] + "include": ["src/"] } diff --git a/packages/@lwc/engine-server/scripts/rollup.config.js b/packages/@lwc/engine-server/scripts/rollup.config.js deleted file mode 100644 index 762be05be4..0000000000 --- a/packages/@lwc/engine-server/scripts/rollup.config.js +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ - -const path = require('path'); -const { nodeResolve } = require('@rollup/plugin-node-resolve'); -const replace = require('@rollup/plugin-replace'); -const typescript = require('../../../../scripts/rollup/typescript'); -const writeDistAndTypes = require('../../../../scripts/rollup/writeDistAndTypes'); -const { version } = require('../package.json'); - -const banner = `/* proxy-compat-disable */`; -const footer = `/* version: ${version} */`; -const formats = ['es', 'cjs']; - -module.exports = { - input: path.resolve(__dirname, '../src/index.ts'), - - output: formats.map((format) => { - return { - file: `engine-server${format === 'cjs' ? '.cjs' : ''}.js`, - sourcemap: true, - format, - banner: banner, - footer: footer, - }; - }), - - plugins: [ - nodeResolve({ - resolveOnly: [/^@lwc\//], - }), - typescript(), - writeDistAndTypes(), - replace({ - values: { - 'process.env.IS_BROWSER': 'false', - }, - preventAssignment: true, - }), - ], - - onwarn({ code, message }) { - if (!process.env.ROLLUP_WATCH && code !== 'CIRCULAR_DEPENDENCY') { - throw new Error(message); - } - }, -}; diff --git a/packages/@lwc/engine-server/tsconfig.json b/packages/@lwc/engine-server/tsconfig.json index 170ece25f9..6fa56998a0 100644 --- a/packages/@lwc/engine-server/tsconfig.json +++ b/packages/@lwc/engine-server/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../../../tsconfig.json", "compilerOptions": { - "outDir": ".", "lib": ["dom", "es2018"] }, diff --git a/packages/@lwc/errors/tsconfig.json b/packages/@lwc/errors/tsconfig.json index 3c88a3786f..af627f6afe 100644 --- a/packages/@lwc/errors/tsconfig.json +++ b/packages/@lwc/errors/tsconfig.json @@ -1,10 +1,5 @@ { "extends": "../../../tsconfig.json", - "compilerOptions": { - "outDir": "dist/commonjs", - "declarationDir": "dist/types" - }, - "include": ["src/"] } diff --git a/packages/@lwc/features/scripts/rollup/rollup.config.js b/packages/@lwc/features/scripts/rollup/rollup.config.js deleted file mode 100644 index ed9d47a37b..0000000000 --- a/packages/@lwc/features/scripts/rollup/rollup.config.js +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ -const path = require('path'); -const { nodeResolve } = require('@rollup/plugin-node-resolve'); -const typescript = require('../../../../../scripts/rollup/typescript'); -const writeDistAndTypes = require('../../../../../scripts/rollup/writeDistAndTypes'); -const { version, dependencies, peerDependencies } = require('../../package.json'); -const entry = path.resolve(__dirname, '../../src/flags.ts'); -const banner = `/**\n * Copyright (C) 2018 salesforce.com, inc.\n */`; -const footer = `/** version: ${version} */`; - -function generateTargetName({ format }) { - return ['flags', format === 'cjs' ? '.cjs' : '', '.js'].join(''); -} - -function rollupConfig({ format }) { - return { - input: entry, - output: { - file: generateTargetName({ format }), - sourcemap: true, - format, - banner, - footer, - exports: 'named', - }, - plugins: [ - nodeResolve({ - resolveOnly: [/^@lwc\//], - }), - typescript(), - writeDistAndTypes(), - ], - external: [...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {})], - }; -} - -module.exports = [rollupConfig({ format: 'es' }), rollupConfig({ format: 'cjs' })]; diff --git a/packages/@lwc/features/src/__tests__/features.spec.ts b/packages/@lwc/features/src/__tests__/features.spec.ts index 2abd7173e0..74a2d0262d 100644 --- a/packages/@lwc/features/src/__tests__/features.spec.ts +++ b/packages/@lwc/features/src/__tests__/features.spec.ts @@ -5,7 +5,7 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ -import features from '../flags'; +import features from '../index'; describe('features', () => { it('known flags in the features map are null', () => { diff --git a/packages/@lwc/features/src/__tests__/lwcRuntimeFlags.spec.ts b/packages/@lwc/features/src/__tests__/lwcRuntimeFlags.spec.ts index 42d2b2147f..7373fa35e6 100644 --- a/packages/@lwc/features/src/__tests__/lwcRuntimeFlags.spec.ts +++ b/packages/@lwc/features/src/__tests__/lwcRuntimeFlags.spec.ts @@ -5,7 +5,7 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ -import { lwcRuntimeFlags } from '../flags'; +import { lwcRuntimeFlags } from '../index'; describe('lwcRuntimeFlags', () => { it('known flags default to undefined', () => { diff --git a/packages/@lwc/features/src/__tests__/setFeatureFlag.spec.ts b/packages/@lwc/features/src/__tests__/setFeatureFlag.spec.ts index 1fe2ab8355..4eb8485913 100644 --- a/packages/@lwc/features/src/__tests__/setFeatureFlag.spec.ts +++ b/packages/@lwc/features/src/__tests__/setFeatureFlag.spec.ts @@ -5,7 +5,7 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ -import { lwcRuntimeFlags, setFeatureFlag } from '../flags'; +import { lwcRuntimeFlags, setFeatureFlag } from '../index'; describe('setFeatureFlag', () => { ['development', 'production'].forEach((env) => { diff --git a/packages/@lwc/features/src/flags.ts b/packages/@lwc/features/src/index.ts similarity index 100% rename from packages/@lwc/features/src/flags.ts rename to packages/@lwc/features/src/index.ts diff --git a/packages/@lwc/features/tsconfig.json b/packages/@lwc/features/tsconfig.json index 1551bcb390..6fa56998a0 100644 --- a/packages/@lwc/features/tsconfig.json +++ b/packages/@lwc/features/tsconfig.json @@ -2,8 +2,6 @@ "extends": "../../../tsconfig.json", "compilerOptions": { - "baseUrl": ".", - "outDir": ".", "lib": ["dom", "es2018"] }, diff --git a/packages/@lwc/module-resolver/tsconfig.json b/packages/@lwc/module-resolver/tsconfig.json index 9c34bec572..af627f6afe 100644 --- a/packages/@lwc/module-resolver/tsconfig.json +++ b/packages/@lwc/module-resolver/tsconfig.json @@ -1,11 +1,5 @@ { "extends": "../../../tsconfig.json", - "compilerOptions": { - "outDir": "dist/commonjs", - "declarationDir": "dist/types" - }, - - "include": ["src/"], - "exclude": ["**/__tests__"] + "include": ["src/"] } diff --git a/packages/@lwc/rollup-plugin/src/index.ts b/packages/@lwc/rollup-plugin/src/index.ts index ddbb147452..5196c78955 100644 --- a/packages/@lwc/rollup-plugin/src/index.ts +++ b/packages/@lwc/rollup-plugin/src/index.ts @@ -46,11 +46,7 @@ export interface RollupLwcOptions { const PLUGIN_NAME = 'rollup-plugin-lwc-compiler'; -const DEFAULT_MODULES = [ - { npm: '@lwc/engine-dom' }, - { npm: '@lwc/synthetic-shadow' }, - { npm: '@lwc/wire-service' }, -]; +const DEFAULT_MODULES = [{ npm: '@lwc/engine-dom' }]; const IMPLICIT_DEFAULT_HTML_PATH = '@lwc/resources/empty_html.js'; const EMPTY_IMPLICIT_HTML_CONTENT = 'export default void 0'; diff --git a/packages/@lwc/rollup-plugin/tsconfig.json b/packages/@lwc/rollup-plugin/tsconfig.json index 3c88a3786f..af627f6afe 100644 --- a/packages/@lwc/rollup-plugin/tsconfig.json +++ b/packages/@lwc/rollup-plugin/tsconfig.json @@ -1,10 +1,5 @@ { "extends": "../../../tsconfig.json", - "compilerOptions": { - "outDir": "dist/commonjs", - "declarationDir": "dist/types" - }, - "include": ["src/"] } diff --git a/packages/@lwc/shared/scripts/rollup/rollup.config.js b/packages/@lwc/shared/scripts/rollup/rollup.config.js deleted file mode 100644 index ddb91c0b26..0000000000 --- a/packages/@lwc/shared/scripts/rollup/rollup.config.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ -const path = require('path'); -const replace = require('@rollup/plugin-replace'); -const typescript = require('../../../../../scripts/rollup/typescript'); -const writeDistAndTypes = require('../../../../../scripts/rollup/writeDistAndTypes'); -const { version } = require('../../package.json'); -const entry = path.resolve(__dirname, '../../src/index.ts'); -const banner = `/**\n * Copyright (C) 2018 salesforce.com, inc.\n */`; -const footer = `/** version: ${version} */`; - -function generateTargetName({ format }) { - return ['index', format === 'cjs' ? '.cjs' : '', '.js'].join(''); -} - -function rollupConfig({ format }) { - return { - input: entry, - output: { - file: generateTargetName({ format }), - sourcemap: true, - format, - banner, - footer, - }, - plugins: [ - replace({ - preventAssignment: true, - 'process.env.LWC_VERSION': JSON.stringify(version), - }), - typescript(), - writeDistAndTypes(), - ], - }; -} - -module.exports = [rollupConfig({ format: 'es' }), rollupConfig({ format: 'cjs' })]; diff --git a/packages/@lwc/shared/tsconfig.json b/packages/@lwc/shared/tsconfig.json index d85fcf5681..af627f6afe 100644 --- a/packages/@lwc/shared/tsconfig.json +++ b/packages/@lwc/shared/tsconfig.json @@ -1,9 +1,5 @@ { "extends": "../../../tsconfig.json", - "compilerOptions": { - "baseUrl": ".", - "outDir": "." - }, "include": ["src/"] } diff --git a/packages/@lwc/style-compiler/tsconfig.json b/packages/@lwc/style-compiler/tsconfig.json index 3c88a3786f..af627f6afe 100644 --- a/packages/@lwc/style-compiler/tsconfig.json +++ b/packages/@lwc/style-compiler/tsconfig.json @@ -1,10 +1,5 @@ { "extends": "../../../tsconfig.json", - "compilerOptions": { - "outDir": "dist/commonjs", - "declarationDir": "dist/types" - }, - "include": ["src/"] } diff --git a/packages/@lwc/synthetic-shadow/scripts/rollup/rollup.config.js b/packages/@lwc/synthetic-shadow/scripts/rollup/rollup.config.js deleted file mode 100644 index 5fdabb66e0..0000000000 --- a/packages/@lwc/synthetic-shadow/scripts/rollup/rollup.config.js +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ -const path = require('path'); -const { nodeResolve } = require('@rollup/plugin-node-resolve'); -const typescript = require('../../../../../scripts/rollup/typescript'); -const { version } = require('../../package.json'); - -const entry = path.resolve(__dirname, '../../src/index.ts'); -const targetDirectory = path.resolve(__dirname, '../../dist/'); -const targetName = 'synthetic-shadow.js'; -const banner = `/* proxy-compat-disable */`; -const footer = `/** version: ${version} */`; - -function wrapModule() { - return { - renderChunk(code) { - return `${banner}\nexport default function enableSyntheticShadow() {\n${code}\n}`; - }, - }; -} - -function rollupConfig({ wrap } = {}) { - return { - input: entry, - output: { - sourcemap: true, - file: path.join(targetDirectory, targetName), - name: 'SyntheticShadow', - format: 'es', - banner, - footer, - }, - plugins: [ - wrap && wrapModule(), - nodeResolve({ - only: [/^@lwc\//], - }), - typescript(), - ].filter(Boolean), - onwarn({ code, message }) { - if (!process.env.ROLLUP_WATCH && code !== 'CIRCULAR_DEPENDENCY') { - throw new Error(message); - } - }, - }; -} - -module.exports = [ - // Wrap encloses de module into a function so it can be conditionally enabled at runtime - // This is very useful for testing. - //rollupConfig({ format: 'es', target: 'es2017', wrap: true }), - - rollupConfig(), -]; diff --git a/packages/@lwc/synthetic-shadow/tsconfig.json b/packages/@lwc/synthetic-shadow/tsconfig.json index 4a60d88ea1..6fa56998a0 100644 --- a/packages/@lwc/synthetic-shadow/tsconfig.json +++ b/packages/@lwc/synthetic-shadow/tsconfig.json @@ -2,10 +2,7 @@ "extends": "../../../tsconfig.json", "compilerOptions": { - "lib": ["dom", "es2018"], - "outDir": "dist", - "declaration": false, - "declarationDir": null + "lib": ["dom", "es2018"] }, "include": ["src/"] diff --git a/packages/@lwc/template-compiler/typings/parse5-internals.d.ts b/packages/@lwc/template-compiler/src/typings/parse5-internals.d.ts similarity index 100% rename from packages/@lwc/template-compiler/typings/parse5-internals.d.ts rename to packages/@lwc/template-compiler/src/typings/parse5-internals.d.ts diff --git a/packages/@lwc/template-compiler/typings/parse5.d.ts b/packages/@lwc/template-compiler/src/typings/parse5.d.ts similarity index 100% rename from packages/@lwc/template-compiler/typings/parse5.d.ts rename to packages/@lwc/template-compiler/src/typings/parse5.d.ts diff --git a/packages/@lwc/template-compiler/typings/parse5errors.d.ts b/packages/@lwc/template-compiler/src/typings/parse5errors.d.ts similarity index 100% rename from packages/@lwc/template-compiler/typings/parse5errors.d.ts rename to packages/@lwc/template-compiler/src/typings/parse5errors.d.ts diff --git a/packages/@lwc/template-compiler/tsconfig.json b/packages/@lwc/template-compiler/tsconfig.json index b7c92ec45e..af627f6afe 100644 --- a/packages/@lwc/template-compiler/tsconfig.json +++ b/packages/@lwc/template-compiler/tsconfig.json @@ -1,10 +1,5 @@ { "extends": "../../../tsconfig.json", - "compilerOptions": { - "outDir": "dist/commonjs", - "declarationDir": "dist/types" - }, - - "include": ["src/", "typings/"] + "include": ["src/"] } diff --git a/packages/@lwc/wire-service/scripts/rollup/rollup.config.js b/packages/@lwc/wire-service/scripts/rollup/rollup.config.js deleted file mode 100644 index cfafc44ce7..0000000000 --- a/packages/@lwc/wire-service/scripts/rollup/rollup.config.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ -const path = require('path'); -const { nodeResolve } = require('@rollup/plugin-node-resolve'); -const typescript = require('../../../../../scripts/rollup/typescript'); -const writeDistAndTypes = require('../../../../../scripts/rollup/writeDistAndTypes'); -const { version } = require('../../package.json'); -const entry = path.resolve(__dirname, '../../src/index.ts'); -const banner = `/**\n * Copyright (C) 2018 salesforce.com, inc.\n */`; -const footer = `/** version: ${version} */`; - -function generateTargetName({ format }) { - return ['wire-service', format === 'cjs' ? '.cjs' : '', '.js'].join(''); -} - -function rollupConfig({ format }) { - return { - input: entry, - output: { - file: generateTargetName({ format }), - sourcemap: true, - name: 'WireService', - format, - banner, - footer, - }, - plugins: [ - nodeResolve({ - only: [/^@lwc\//], - }), - typescript(), - writeDistAndTypes(), - ], - }; -} - -module.exports = [rollupConfig({ format: 'es' }), rollupConfig({ format: 'cjs' })]; diff --git a/packages/@lwc/wire-service/tsconfig.json b/packages/@lwc/wire-service/tsconfig.json index 170ece25f9..6fa56998a0 100644 --- a/packages/@lwc/wire-service/tsconfig.json +++ b/packages/@lwc/wire-service/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../../../tsconfig.json", "compilerOptions": { - "outDir": ".", "lib": ["dom", "es2018"] }, diff --git a/packages/lwc/scripts/utils/helpers.js b/packages/lwc/scripts/utils/helpers.js index f8bf5b6a47..ad797332ee 100644 --- a/packages/lwc/scripts/utils/helpers.js +++ b/packages/lwc/scripts/utils/helpers.js @@ -15,7 +15,7 @@ function createDir(dir) { } function getEs6ModuleEntry(pkg) { - const pkgFilePath = require.resolve(`${pkg}/package.json`); + const pkgFilePath = path.resolve(__dirname, '../../../', pkg, './package.json'); const pkgDir = path.dirname(pkgFilePath); const pkgJson = JSON.parse(fs.readFileSync(pkgFilePath, 'utf8')); return path.join(pkgDir, pkgJson.module); diff --git a/packages/@lwc/engine-dom/scripts/rollup.config.js b/scripts/rollup/rollup.config.js similarity index 62% rename from packages/@lwc/engine-dom/scripts/rollup.config.js rename to scripts/rollup/rollup.config.js index a8ceede499..308ce1a85b 100644 --- a/packages/@lwc/engine-dom/scripts/rollup.config.js +++ b/scripts/rollup/rollup.config.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, salesforce.com, inc. + * Copyright (c) 2023, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT @@ -7,28 +7,45 @@ /* eslint-env node */ -const path = require('path'); +const fs = require('node:fs'); +const path = require('node:path'); +const MagicString = require('magic-string'); const { rollup } = require('rollup'); -const { nodeResolve } = require('@rollup/plugin-node-resolve'); const replace = require('@rollup/plugin-replace'); -const MagicString = require('magic-string'); -const typescript = require('../../../../scripts/rollup/typescript'); -const writeDistAndTypes = require('../../../../scripts/rollup/writeDistAndTypes'); -const { version } = require('../package.json'); +const typescript = require('@rollup/plugin-typescript'); +const { nodeResolve } = require('@rollup/plugin-node-resolve'); -const banner = `/* proxy-compat-disable */`; -const footer = `/* version: ${version} */`; +const pkg = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), 'utf-8')); +const { version, dependencies, peerDependencies } = pkg; +const banner = `/**\n * Copyright (C) 2023 salesforce.com, inc.\n */`; +const footer = `/** version: ${version} */`; +const { ROLLUP_WATCH: watchMode } = process.env; const formats = ['es', 'cjs']; const RENDERER_REPLACEMENT_STRING = 'process.env.RENDERER'; +const onwarn = ({ code, message }) => { + if (!process.env.ROLLUP_WATCH && code !== 'CIRCULAR_DEPENDENCY') { + throw new Error(message); + } +}; + // These plugins are used both by the main Rollup build as well as our sub-Rollup build (injectInlineRenderer). function sharedPlugins() { return [ - typescript(), + typescript({ + target: 'es2017', + tsconfig: path.join(process.cwd(), 'tsconfig.json'), + noEmitOnError: !watchMode, // in watch mode, do not exit with an error if typechecking fails + ...(watchMode && { + incremental: true, + outputToFilesystem: true, + }), + }), replace({ values: { 'process.env.IS_BROWSER': 'true', + 'process.env.LWC_VERSION': JSON.stringify(version), }, preventAssignment: true, }), @@ -36,6 +53,7 @@ function sharedPlugins() { } function injectInlineRenderer() { + // Only used for @lwc/engine-dom // The renderer in the renderer factory needs to be inlined in the function, with all of its dependencies. // The reasons for this are due to how Locker does sandboxing. // So we run Rollup inside of a Rollup plugin to accomplish this. This resolves all dependencies and @@ -46,7 +64,10 @@ function injectInlineRenderer() { async transform(source) { if (source.includes(RENDERER_REPLACEMENT_STRING)) { const bundle = await rollup({ - input: path.resolve(__dirname, '../src/renderer/index.ts'), + input: path.resolve( + __dirname, + '../../packages/@lwc/engine-dom/src/renderer/index.ts' + ), plugins: [ // In the inline renderer, we only allow certain dependencies. Any others should fail @@ -55,8 +76,11 @@ function injectInlineRenderer() { }), ...sharedPlugins(), ], + + onwarn, }); const { output } = await bundle.generate({ + sourcemap: true, name: 'renderer', format: 'iife', esModule: false, // no need for `Object.defineProperty(exports, '__esModule', { value: true })` @@ -85,30 +109,37 @@ function injectInlineRenderer() { } module.exports = { - input: path.resolve(__dirname, '../src/index.ts'), + input: path.resolve(process.cwd(), './src/index.ts'), output: formats.map((format) => { return { - file: `engine-dom${format === 'cjs' ? '.cjs' : ''}.js`, + file: `dist/index${format === 'cjs' ? '.cjs' : ''}.js`, sourcemap: true, format, - banner: banner, - footer: footer, + banner, + footer, + exports: 'named', + esModule: true, }; }), plugins: [ nodeResolve({ - resolveOnly: [/^@lwc\//], + resolveOnly: [/^@lwc\//, 'observable-membrane'], }), ...sharedPlugins(), - writeDistAndTypes(), injectInlineRenderer(), ], - onwarn({ code, message }) { - if (!process.env.ROLLUP_WATCH && code !== 'CIRCULAR_DEPENDENCY') { - throw new Error(message); - } - }, + onwarn, + + external: [ + ...Object.keys(dependencies || {}), + ...Object.keys(peerDependencies || {}), + // node-internal dependencies should be listed here + 'fs', + 'path', + // FIXME: should not have to manually declare this + 'parse5/lib/parser', + ], }; diff --git a/scripts/rollup/typescript.js b/scripts/rollup/typescript.js deleted file mode 100644 index b889042af1..0000000000 --- a/scripts/rollup/typescript.js +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ -const path = require('path'); -const typescriptPlugin = require('@rollup/plugin-typescript'); - -const { ROLLUP_WATCH: watchMode } = process.env; - -// Basic @rollup/plugin-typescript config that can be shared between packages -module.exports = function typescript() { - return typescriptPlugin({ - target: 'es2017', - tsconfig: path.join(process.cwd(), 'tsconfig.json'), - noEmitOnError: !watchMode, // in watch mode, do not exit with an error if typechecking fails - ...(watchMode && { - incremental: true, - outputToFilesystem: true, - }), - }); -}; diff --git a/scripts/rollup/writeDistAndTypes.js b/scripts/rollup/writeDistAndTypes.js deleted file mode 100644 index 95f36e63db..0000000000 --- a/scripts/rollup/writeDistAndTypes.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ -const path = require('path'); - -/** - * Small Rollup plugin that writes JavaScript files to `dist/` and TypeScript declaration files to - * 'types/`. The reason for this is that `@rollup/plugin-typescript` doesn't make it possible to - * write the two file types to two separate directories (without having `types` inside of `dist`). - * See: https://github.com/rollup/plugins/blob/e32a9e9/packages/typescript/test/test.js#L52 - */ -module.exports = function writeDistAndTypes() { - return { - id: 'write-dist-and-types', - generateBundle(options, bundle) { - for (const [id, descriptor] of Object.entries(bundle)) { - const directory = id.endsWith('.d.ts') ? 'types' : 'dist'; - descriptor.fileName = path.join(directory, descriptor.fileName); - } - return null; - }, - }; -}; diff --git a/scripts/tasks/check-and-rewrite-package-json.js b/scripts/tasks/check-and-rewrite-package-json.js new file mode 100644 index 0000000000..7cb978b486 --- /dev/null +++ b/scripts/tasks/check-and-rewrite-package-json.js @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * SPDX-License-Identifier: MIT + * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT + */ + +// Checks that various package.json files are structured the way we expect. +// Errors if the files are different, and writes the changed files to disk. +// +// The goals are: +// 1. to avoid having to manually keep package.json files in sync with each other +// 2. to have a consistent format for all the package.jsons we publish to npm + +const fs = require('fs'); +const path = require('path'); +const { globSync } = require('glob'); + +const ignoredPackages = [ + 'packages/@lwc/integration-karma', + 'packages/@lwc/integration-test', + 'packages/@lwc/perf-benchmarks', + 'packages/@lwc/perf-benchmarks-components', +]; + +const directories = globSync('./packages/@lwc/*').filter((_) => !ignoredPackages.includes(_)); + +const expectedPkgJsons = []; + +for (const dir of directories) { + const filename = path.join('./', dir, 'package.json'); + const actual = fs.readFileSync(filename, 'utf-8'); + const pkg = JSON.parse(actual); + + const { name, description, version, dependencies, devDependencies, peerDependencies } = pkg; + let { keywords } = pkg; + + keywords = [...new Set((keywords || []).concat(['lwc']))].sort(); + + const expectedJson = { + name, + version, + description, + homepage: 'https://lwc.dev', + repository: { + type: 'git', + url: 'https://github.com/salesforce/lwc.git', + directory: `packages/${name}`, + }, + bugs: { url: 'https://github.com/salesforce/lwc/issues' }, + license: 'MIT', + publishConfig: { access: 'public' }, + main: './dist/index.cjs.js', + module: './dist/index.js', + types: './dist/index.d.ts', + files: ['./dist'], + scripts: { + build: 'rollup --config ../../../scripts/rollup/rollup.config.js', + dev: 'rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen', + }, + nx: { + targets: { + build: { + outputs: ['./dist'], + }, + }, + }, + dependencies, + devDependencies, + peerDependencies, + }; + + if (name === '@lwc/engine-dom') { + // Special case - consumers can do `import { LightningElement } 'lwc'` and have it resolve to `@lwc/engine-dom` + expectedJson.lwc = { + modules: [ + { + name: 'lwc', + path: 'dist/index.js', + }, + ], + expose: ['lwc'], + }; + } + + const expected = JSON.stringify(expectedJson, null, 4); + + expectedPkgJsons.push({ + filename, + expected, + actual, + }); +} + +// Check if any of the files are different than what we expect, so we can error in that case +const differingPackageJsonFiles = []; + +for (const { filename, expected, actual } of expectedPkgJsons) { + if (actual !== expected) { + differingPackageJsonFiles.push(filename); + fs.writeFileSync(filename, expected, 'utf-8'); + } +} + +if (differingPackageJsonFiles.length > 0) { + console.error( + 'Found package.json files with unexpected content. Content has been overwritten.\n' + + 'Please run `git commit` and `node ./scripts/tasks/check-and-rewrite-package-json.js` again.\n' + + 'Files:', + differingPackageJsonFiles + ); + process.exit(1); +} diff --git a/tsconfig.json b/tsconfig.json index 2ee82b2d1d..c88db46f82 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,10 @@ "lib": ["es2018"], // Disable automatic inclusion of @types packages - "types": ["node", "jest"] + "types": ["node", "jest"], + + "outDir": "dist", + "declarationDir": "dist" }, "exclude": [