-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react): add format option for buildable libs
- Clean up @nrwl/web:package executor - Combine react package e2e tests to speed up test time
- Loading branch information
Showing
18 changed files
with
631 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { normalizePackageOptions } from './normalize'; | ||
import { WebPackageOptions } from '../schema'; | ||
|
||
describe('normalizePackageOptions', () => { | ||
let testOptions: WebPackageOptions; | ||
let root: string; | ||
let sourceRoot: string; | ||
|
||
beforeEach(() => { | ||
testOptions = { | ||
outputPath: '/tmp', | ||
project: 'apps/nodeapp/package.json', | ||
entryFile: 'apps/nodeapp/src/main.ts', | ||
tsConfig: 'apps/nodeapp/tsconfig.app.json', | ||
rollupConfig: 'apps/nodeapp/rollup.config', | ||
format: ['esm'], | ||
}; | ||
root = '/root'; | ||
sourceRoot = 'apps/nodeapp/src'; | ||
}); | ||
|
||
it('should resolve both node modules and relative path for rollupConfig', () => { | ||
let result = normalizePackageOptions(testOptions, root, sourceRoot); | ||
expect(result.rollupConfig).toEqual(['/root/apps/nodeapp/rollup.config']); | ||
|
||
result = normalizePackageOptions( | ||
{ | ||
...testOptions, | ||
// something that exists in node_modules | ||
rollupConfig: 'react', | ||
}, | ||
root, | ||
sourceRoot | ||
); | ||
expect(result.rollupConfig).toHaveLength(1); | ||
expect(result.rollupConfig[0]).toMatch('react'); | ||
expect(result.rollupConfig[0]).not.toMatch(root); | ||
}); | ||
|
||
it('should handle rollupConfig being undefined', () => { | ||
delete testOptions.rollupConfig; | ||
|
||
const result = normalizePackageOptions(testOptions, root, sourceRoot); | ||
expect(result.rollupConfig).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { dirname } from 'path'; | ||
|
||
import { AssetGlobPattern } from '../../../utils/types'; | ||
import { normalizeAssets, normalizePluginPath } from '../../../utils/normalize'; | ||
import { WebPackageOptions } from '../schema'; | ||
|
||
export interface NormalizedWebPackageOptions extends WebPackageOptions { | ||
entryRoot: string; | ||
projectRoot: string; | ||
assets: AssetGlobPattern[]; | ||
rollupConfig: string[]; | ||
} | ||
|
||
export function normalizePackageOptions( | ||
options: WebPackageOptions, | ||
root: string, | ||
sourceRoot: string | ||
): NormalizedWebPackageOptions { | ||
const entryFile = `${root}/${options.entryFile}`; | ||
const entryRoot = dirname(entryFile); | ||
const project = `${root}/${options.project}`; | ||
const projectRoot = dirname(project); | ||
const outputPath = `${root}/${options.outputPath}`; | ||
|
||
if (options.buildableProjectDepsInPackageJsonType == undefined) { | ||
options.buildableProjectDepsInPackageJsonType = 'peerDependencies'; | ||
} | ||
|
||
return { | ||
...options, | ||
// de-dupe formats | ||
format: Array.from(new Set(options.format)), | ||
rollupConfig: [] | ||
.concat(options.rollupConfig) | ||
.filter(Boolean) | ||
.map((p) => normalizePluginPath(p, root)), | ||
assets: options.assets | ||
? normalizeAssets(options.assets, root, sourceRoot) | ||
: undefined, | ||
entryFile, | ||
entryRoot, | ||
project, | ||
projectRoot, | ||
outputPath, | ||
}; | ||
} |
File renamed without changes.
Oops, something went wrong.