diff --git a/.changeset/large-icons-jump.md b/.changeset/large-icons-jump.md new file mode 100644 index 000000000..07b8523b1 --- /dev/null +++ b/.changeset/large-icons-jump.md @@ -0,0 +1,5 @@ +--- +'modular-scripts': patch +--- + +Fix repository field generation on Windows diff --git a/.changeset/slow-buckets-wash.md b/.changeset/slow-buckets-wash.md new file mode 100644 index 000000000..45729be9b --- /dev/null +++ b/.changeset/slow-buckets-wash.md @@ -0,0 +1,6 @@ +--- +'modular-scripts': minor +--- + +- Fix prefixed logger debug method logging as info +- Copy LICENSE files when building packages diff --git a/.changeset/tall-turtles-think.md b/.changeset/tall-turtles-think.md new file mode 100644 index 000000000..2b01ad9b3 --- /dev/null +++ b/.changeset/tall-turtles-think.md @@ -0,0 +1,10 @@ +--- +'modular-scripts': patch +'modular-template-app': patch +'modular-template-esm-view': patch +'modular-template-node-env-app': patch +'modular-template-package': patch +'modular-template-view': patch +--- + +Remove explicit package.json and license entry in files array diff --git a/packages/modular-scripts/src/__tests__/build.test.ts b/packages/modular-scripts/src/__tests__/build.test.ts index c77de371f..71953bc42 100644 --- a/packages/modular-scripts/src/__tests__/build.test.ts +++ b/packages/modular-scripts/src/__tests__/build.test.ts @@ -40,7 +40,6 @@ describe('WHEN building with preserve modules', () => { "dist-cjs", "dist-es", "dist-types", - "README.md", ], "main": "dist-cjs/index.js", "modular": { @@ -64,6 +63,7 @@ describe('WHEN building with preserve modules', () => { expect(tree(path.join(modularRoot, 'dist', packageName))) .toMatchInlineSnapshot(` "sample-async-package + ├─ LICENSE #1gat5ri ├─ dist-cjs │ ├─ index.js #p1m6x9 │ ├─ index.js.map #16jes1h @@ -181,6 +181,7 @@ describe('WHEN building packages with private cross-package dependencies', () => expect(tree(path.join(modularRoot, 'dist', dependentPackage))) .toMatchInlineSnapshot(` "sample-depending-package + ├─ LICENSE #1gat5ri ├─ dist-cjs │ ├─ index.js #1m9v9ya │ ├─ index.js.map #79ot9r diff --git a/packages/modular-scripts/src/__tests__/index.test.ts b/packages/modular-scripts/src/__tests__/index.test.ts index 0a7a37442..518772bde 100644 --- a/packages/modular-scripts/src/__tests__/index.test.ts +++ b/packages/modular-scripts/src/__tests__/index.test.ts @@ -209,7 +209,6 @@ describe('modular-scripts', () => { "dist-cjs", "dist-es", "dist-types", - "README.md", ], "main": "dist-cjs/index.js", "modular": { @@ -293,6 +292,7 @@ describe('modular-scripts', () => { expect(tree(path.join(modularRoot, 'dist', 'sample-view'))) .toMatchInlineSnapshot(` "sample-view + ├─ LICENSE #1gat5ri ├─ dist-cjs │ ├─ index.js #p1m6x9 │ ├─ index.js.map #16jes1h @@ -361,7 +361,6 @@ describe('modular-scripts', () => { "dist-cjs", "dist-es", "dist-types", - "README.md", ], "main": "dist-cjs/index.js", "modular": { @@ -385,6 +384,7 @@ describe('modular-scripts', () => { expect(tree(path.join(modularRoot, 'dist', 'sample-package'))) .toMatchInlineSnapshot(` "sample-package + ├─ LICENSE #1gat5ri ├─ dist-cjs │ ├─ index.js #p1m6x9 │ ├─ index.js.map #16jes1h @@ -442,7 +442,6 @@ describe('modular-scripts', () => { "dist-cjs", "dist-es", "dist-types", - "README.md", ], "main": "dist-cjs/nested-sample-package.cjs.js", "modular": { @@ -466,6 +465,7 @@ describe('modular-scripts', () => { expect(tree(path.join(modularRoot, 'dist', 'nested-sample-package'))) .toMatchInlineSnapshot(` "nested-sample-package + ├─ LICENSE #1gat5ri ├─ dist-cjs │ ├─ nested-sample-package.cjs.js #kv2xzp │ └─ nested-sample-package.cjs.js.map #1vw1uze diff --git a/packages/modular-scripts/src/build/buildPackage/getRepositoryField.ts b/packages/modular-scripts/src/build/buildPackage/getRepositoryField.ts index e5b4dc099..6fc95a390 100644 --- a/packages/modular-scripts/src/build/buildPackage/getRepositoryField.ts +++ b/packages/modular-scripts/src/build/buildPackage/getRepositoryField.ts @@ -11,7 +11,10 @@ async function getRelativePathInRepo(packagePath: string) { ['rev-parse', '--show-toplevel'], { stdout: 'pipe' }, ); - return path.relative(gitRepoPath, packagePath); + return path + .relative(gitRepoPath, packagePath) + .split(path.win32.sep) + .join(path.posix.sep); } export async function getRepositoryField(packagePath: string) { diff --git a/packages/modular-scripts/src/build/buildPackage/index.ts b/packages/modular-scripts/src/build/buildPackage/index.ts index f05113d82..b6438b691 100644 --- a/packages/modular-scripts/src/build/buildPackage/index.ts +++ b/packages/modular-scripts/src/build/buildPackage/index.ts @@ -17,6 +17,7 @@ import { makeBundle } from './makeBundle'; import { makeTypings } from './makeTypings'; import getRelativeLocation from '../../utils/getRelativeLocation'; import { getRepositoryField } from './getRepositoryField'; +import { maybeCopyRootLicense } from './maybeCopyRootLicense'; const outputDirectory = 'dist'; @@ -84,6 +85,8 @@ export async function buildPackage( ); }); + await maybeCopyRootLicense(target, targetOutputDirectory); + /// and... that's it logger.log(`built ${target} in ${targetOutputDirectory}`); } diff --git a/packages/modular-scripts/src/build/buildPackage/makeBundle.ts b/packages/modular-scripts/src/build/buildPackage/makeBundle.ts index f7fd7b2ff..1679e988b 100644 --- a/packages/modular-scripts/src/build/buildPackage/makeBundle.ts +++ b/packages/modular-scripts/src/build/buildPackage/makeBundle.ts @@ -313,12 +313,15 @@ export async function makeBundle( ...packageJson.dependencies, ...localImports, }, + /** + * Certain files are always included, regardless of settings. + * https://docs.npmjs.com/cli/v9/configuring-npm/package-json#files + */ files: distinct([ ...(packageJson.files || []), 'dist-cjs', 'dist-es', 'dist-types', - 'README.md', ]), }; } diff --git a/packages/modular-scripts/src/build/buildPackage/maybeCopyRootLicense.ts b/packages/modular-scripts/src/build/buildPackage/maybeCopyRootLicense.ts new file mode 100644 index 000000000..656283dfc --- /dev/null +++ b/packages/modular-scripts/src/build/buildPackage/maybeCopyRootLicense.ts @@ -0,0 +1,35 @@ +import * as fs from 'fs-extra'; +import * as path from 'path'; +import globby from 'globby'; +import getPrefixedLogger from '../../utils/getPrefixedLogger'; +import getModularRoot from '../../utils/getModularRoot'; + +const licenseGlob = 'LICEN@(C|S)E*'; + +export async function maybeCopyRootLicense( + target: string, + targetOutputDirectory: string, +) { + const logger = getPrefixedLogger(target); + const modularRoot = getModularRoot(); + const matches = globby.sync(path.join(targetOutputDirectory, licenseGlob), { + cwd: modularRoot, + onlyFiles: true, + }); + if (matches.length === 0) { + logger.debug( + `No license found in ${targetOutputDirectory}. Looking for root license.`, + ); + const rootLicenses = globby.sync(path.join(modularRoot, licenseGlob), { + cwd: modularRoot, + onlyFiles: true, + }); + if (rootLicenses.length > 0) { + rootLicenses.forEach((license) => { + const filename = path.basename(license); + logger.log(`Copying ${filename} found in ${modularRoot}`); + fs.copyFileSync(license, path.join(targetOutputDirectory, filename)); + }); + } + } +} diff --git a/packages/modular-scripts/src/utils/getPrefixedLogger.ts b/packages/modular-scripts/src/utils/getPrefixedLogger.ts index be57148cf..ad7c42e82 100644 --- a/packages/modular-scripts/src/utils/getPrefixedLogger.ts +++ b/packages/modular-scripts/src/utils/getPrefixedLogger.ts @@ -11,7 +11,7 @@ function _getPrefixedLogger(target: string): Logger { logger.clear(); }, debug: (...args: Parameters) => { - logger.log(prefix, ...args); + logger.debug(prefix, ...args); }, log: (...args: Parameters) => { return logger.log(prefix, ...args); diff --git a/packages/modular-template-app/package.json b/packages/modular-template-app/package.json index 073faa940..6b935206c 100644 --- a/packages/modular-template-app/package.json +++ b/packages/modular-template-app/package.json @@ -10,7 +10,6 @@ }, "license": "Apache-2.0", "files": [ - "README.md", "public", "src" ] diff --git a/packages/modular-template-esm-view/package.json b/packages/modular-template-esm-view/package.json index be8f8dfee..a88da6ac0 100644 --- a/packages/modular-template-esm-view/package.json +++ b/packages/modular-template-esm-view/package.json @@ -10,7 +10,6 @@ }, "license": "Apache-2.0", "files": [ - "README.md", "src" ] } diff --git a/packages/modular-template-node-env-app/package.json b/packages/modular-template-node-env-app/package.json index cda985f6e..d9bc62f93 100644 --- a/packages/modular-template-node-env-app/package.json +++ b/packages/modular-template-node-env-app/package.json @@ -14,7 +14,6 @@ }, "license": "Apache-2.0", "files": [ - "README.md", "public", "src" ] diff --git a/packages/modular-template-package/package.json b/packages/modular-template-package/package.json index 4ec33c070..3d4c74a80 100644 --- a/packages/modular-template-package/package.json +++ b/packages/modular-template-package/package.json @@ -11,7 +11,6 @@ }, "license": "Apache-2.0", "files": [ - "README.md", "src" ] } diff --git a/packages/modular-template-view/package.json b/packages/modular-template-view/package.json index 65ffb6443..f7010a9f1 100644 --- a/packages/modular-template-view/package.json +++ b/packages/modular-template-view/package.json @@ -11,7 +11,6 @@ "templateType": "view" }, "files": [ - "README.md", "src" ] }