diff --git a/package.json b/package.json index 7ac67ba7eb9..eb3e970b12d 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,8 @@ "update-version": "node ./scripts/updateVersion", "update-tsconfig": "node ./scripts/update-tsconfig", "update-flowconfig": "node ./scripts/update-flowconfig", - "update-packages": "npm run update-version && npm run update-tsconfig && npm run update-flowconfig && npm run update-docs", + "update-www-stubs": "node ./scripts/update-www-stubs", + "update-packages": "npm run update-version && npm run update-tsconfig && npm run update-flowconfig && npm run update-docs && npm run update-www-stubs", "postversion": "git checkout -b ${npm_package_version}__release && npm install && npm run update-version && npm run update-changelog && git add -A && git commit -m v${npm_package_version} && git tag -a v${npm_package_version} -m v${npm_package_version}", "publish-extension": "npm run zip -w @lexical/devtools && npm run publish -w @lexical/devtools", "release": "npm run prepare-release && node ./scripts/npm/release.js", diff --git a/packages/lexical-website/docs/maintainers-guide.md b/packages/lexical-website/docs/maintainers-guide.md index ca3221a66b9..cecf2f0b9f8 100644 --- a/packages/lexical-website/docs/maintainers-guide.md +++ b/packages/lexical-website/docs/maintainers-guide.md @@ -47,7 +47,7 @@ not ready for consumption, it should probably still be set to | Unit Tests | `packages/lexical-package-name/src/__tests__/unit/LexicalPackageName.test.{ts,tsx}` | | dist (gitignore'd build product) | `packages/lexical-package-name/dist` | | npm (gitignore'd prerelease product) | `packages/lexical-package-name/npm` | -| www entrypoint? | `packages/lexical-package-name/LexicalPackageName.js` | +| www entrypoint | `packages/lexical-package-name/LexicalPackageName.js` | ### Multiple module export (@lexical/react) @@ -181,10 +181,11 @@ describe('LexicalEslintPlugin', () => { ### npm run update-packages -This script runs: update-version, update-tsconfig, update-flowconfig, and -update-docs. This is safe to do at any time and will ensure that package.json -files are all at the correct versions, paths are set up correctly for module -resolution of all public exports, and that various defaults are filled in. +This script runs: update-version, update-tsconfig, update-flowconfig, +update-docs, and update-www-stubs. This is safe to do at any time and will +ensure that package.json files are all at the correct versions, paths are +set up correctly for module resolution of all public exports, and that +various defaults are filled in. These scripts can be run individually, but unless you're working on one of these scripts you might as well run them all. diff --git a/scripts/__tests__/unit/build.test.js b/scripts/__tests__/unit/build.test.js index 6e551995474..db2a9c1f413 100644 --- a/scripts/__tests__/unit/build.test.js +++ b/scripts/__tests__/unit/build.test.js @@ -12,6 +12,7 @@ const fs = require('fs-extra'); const glob = require('glob'); const path = require('node:path'); const {packagesManager} = require('../../shared/packagesManager'); +const npmToWwwName = require('../../www/npmToWwwName'); const monorepoPackageJson = require('../../shared/readMonorepoPackageJson')(); @@ -19,7 +20,7 @@ const publicNpmNames = new Set( packagesManager.getPublicPackages().map((pkg) => pkg.getNpmName()), ); -describe('public package.json audits (`npm run update-version` to fix most issues)', () => { +describe('public package.json audits (`npm run update-packages` to fix most issues)', () => { packagesManager.getPublicPackages().forEach((pkg) => { const npmName = pkg.getNpmName(); const packageJson = pkg.packageJson; @@ -91,7 +92,7 @@ describe('public package.json audits (`npm run update-version` to fix most issue }); }); -describe('documentation audits (`npm run update-docs` to fix most issues)', () => { +describe('documentation audits (`npm run update-packages` to fix most issues)', () => { const webPkg = packagesManager.getPackageByDirectoryName('lexical-website'); packagesManager.getPublicPackages().forEach((pkg) => { const npmName = pkg.getNpmName(); @@ -115,3 +116,21 @@ describe('documentation audits (`npm run update-docs` to fix most issues)', () = }); }); }); + +describe('www public package audits (`npm run update-packages` to fix most issues)', () => { + packagesManager.getPublicPackages().forEach((pkg) => { + const npmName = pkg.getNpmName(); + const wwwEntrypoint = `${npmToWwwName(npmName)}.js`; + describe(npmName, () => { + it('has *.flow types', () => { + expect(glob.sync(pkg.resolve('flow', '*.flow'))).not.toEqual([]); + }); + // Only worry about the entrypoint stub if it has a single module export + if (pkg.getExportedNpmModuleNames().every((name) => name === npmName)) { + it(`has a packages/${pkg.getDirectoryName()}/${wwwEntrypoint}`, () => { + expect(fs.existsSync(pkg.resolve(wwwEntrypoint))).toBe(true); + }); + } + }); + }); +}); diff --git a/scripts/update-www-stubs.js b/scripts/update-www-stubs.js new file mode 100644 index 00000000000..b4590947302 --- /dev/null +++ b/scripts/update-www-stubs.js @@ -0,0 +1,61 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ +// @ts-check +'use strict'; + +const fs = require('fs-extra'); +const path = require('node:path'); +const {packagesManager} = require('./shared/packagesManager'); +const npmToWwwName = require('./www/npmToWwwName'); + +const headerTemplate = fs.readFileSync( + path.resolve(__dirname, 'www', 'headerTemplate.js'), + 'utf8', +); + +/** @param {string} filename */ +function wwwStubTemplate(filename) { + return ` +${headerTemplate} + +'use strict'; + +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +module.exports = require('./dist/${filename}'); +`; +} + +function updateWwwStubs() { + packagesManager.getPublicPackages().forEach((pkg) => { + const npmName = pkg.getNpmName(); + // Only worry about the entrypoint stub if it has a single module export + if (pkg.getExportedNpmModuleNames().some((name) => name !== npmName)) { + return; + } + + const filename = `${npmToWwwName(npmName)}.js`; + const stubPath = pkg.resolve(filename); + const root = pkg.resolve('..', '..'); + + if (!fs.existsSync(stubPath)) { + console.log(`Creating ${path.relative(root, stubPath)}`); + fs.writeFileSync(stubPath, wwwStubTemplate(filename)); + } + }); +} + +updateWwwStubs();