Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into Modular 4 #2237

Merged
merged 7 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/large-icons-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'modular-scripts': patch
---

Fix repository field generation on Windows
6 changes: 6 additions & 0 deletions .changeset/slow-buckets-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'modular-scripts': minor
---

- Fix prefixed logger debug method logging as info
- Copy LICENSE files when building packages
10 changes: 10 additions & 0 deletions .changeset/tall-turtles-think.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion packages/modular-scripts/src/__tests__/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('WHEN building with preserve modules', () => {
"dist-cjs",
"dist-es",
"dist-types",
"README.md",
],
"main": "dist-cjs/index.js",
"modular": {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/modular-scripts/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ describe('modular-scripts', () => {
"dist-cjs",
"dist-es",
"dist-types",
"README.md",
],
"main": "dist-cjs/index.js",
"modular": {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -361,7 +361,6 @@ describe('modular-scripts', () => {
"dist-cjs",
"dist-es",
"dist-types",
"README.md",
],
"main": "dist-cjs/index.js",
"modular": {
Expand All @@ -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
Expand Down Expand Up @@ -442,7 +442,6 @@ describe('modular-scripts', () => {
"dist-cjs",
"dist-es",
"dist-types",
"README.md",
],
"main": "dist-cjs/nested-sample-package.cjs.js",
"modular": {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions packages/modular-scripts/src/build/buildPackage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -84,6 +85,8 @@ export async function buildPackage(
);
});

await maybeCopyRootLicense(target, targetOutputDirectory);

/// and... that's it
logger.log(`built ${target} in ${targetOutputDirectory}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]),
};
}
Original file line number Diff line number Diff line change
@@ -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));
});
}
}
}
2 changes: 1 addition & 1 deletion packages/modular-scripts/src/utils/getPrefixedLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function _getPrefixedLogger(target: string): Logger {
logger.clear();
},
debug: (...args: Parameters<typeof logger.log>) => {
logger.log(prefix, ...args);
logger.debug(prefix, ...args);
},
log: (...args: Parameters<typeof logger.log>) => {
return logger.log(prefix, ...args);
Expand Down
1 change: 0 additions & 1 deletion packages/modular-template-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
"license": "Apache-2.0",
"files": [
"README.md",
"public",
"src"
]
Expand Down
1 change: 0 additions & 1 deletion packages/modular-template-esm-view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
"license": "Apache-2.0",
"files": [
"README.md",
"src"
]
}
1 change: 0 additions & 1 deletion packages/modular-template-node-env-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"license": "Apache-2.0",
"files": [
"README.md",
"public",
"src"
]
Expand Down
1 change: 0 additions & 1 deletion packages/modular-template-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"license": "Apache-2.0",
"files": [
"README.md",
"src"
]
}
1 change: 0 additions & 1 deletion packages/modular-template-view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"templateType": "view"
},
"files": [
"README.md",
"src"
]
}