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

feat(react): support allowJs customization in the rollup executor #16789

Merged
merged 1 commit into from
May 5, 2023
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
10 changes: 5 additions & 5 deletions docs/generated/packages/rollup/executors/rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"x-completion-glob": "tsconfig.*.json",
"x-priority": "important"
},
"allowJs": {
"type": "boolean",
"description": "Allow JavaScript files to be compiled.",
"default": false
},
"format": {
"type": "array",
"description": "List of module formats to output. Defaults to matching format from tsconfig (e.g. CJS for CommonJS, and ESM otherwise).",
Expand Down Expand Up @@ -154,11 +159,6 @@
"type": "boolean",
"description": "Generate package.json with 'exports' field. This field defines entry points in the package and is used by Node and the TypeScript compiler.",
"default": false
},
"skipTypeField": {
"type": "boolean",
"description": "Prevents 'type' field from being added to compiled package.json file. Only use this if you are having an issue with this field.",
"default": false
}
},
"required": ["tsConfig", "main", "outputPath"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,30 +265,4 @@ describe('updatePackageJson', () => {
spy.mockRestore();
});
});

describe('skipTypeField', () => {
it('should not add "type" field in package.json', () => {
const spy = jest.spyOn(utils, 'writeJsonFile');

updatePackageJson(
{
...commonOptions,
format: ['esm'],
skipTypeField: true,
},
sharedContext,
{ type: 'app', name: 'test', data: {} as any },
[],
{} as unknown as PackageJson
);

expect(utils.writeJsonFile).toHaveBeenCalledWith(expect.anything(), {
main: './index.js',
module: './index.js',
types: './index.d.ts',
});

spy.mockRestore();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export function updatePackageJson(
exports['.']['require'] = './index.cjs';
}

if (!options.skipTypeField) {
packageJson.type = options.format.includes('esm') ? 'module' : 'commonjs';
}
packageJson.type = options.format.includes('esm') ? 'module' : 'commonjs';

// Support for older TS versions < 4.5
packageJson.types = types;
Expand Down
6 changes: 3 additions & 3 deletions packages/rollup/src/executors/rollup/rollup.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ export function createRollupOptions(

function createTsCompilerOptions(
config: ts.ParsedCommandLine,
dependencies,
options
dependencies: DependentBuildableProjectNode[],
options: NormalizedRollupExecutorOptions
) {
const compilerOptionPaths = computeCompilerOptionsPaths(config, dependencies);
const compilerOptions = {
rootDir: options.projectRoot,
allowJs: false,
allowJs: options.allowJs,
declaration: true,
paths: compilerOptionPaths,
};
Expand Down
3 changes: 1 addition & 2 deletions packages/rollup/src/executors/rollup/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Globals {
export interface RollupExecutorOptions {
outputPath: string;
tsConfig: string;
allowJs?: boolean;
project: string;
main: string;
outputFileName?: string;
Expand All @@ -29,7 +30,5 @@ export interface RollupExecutorOptions {
format?: string[];
compiler?: 'babel' | 'tsc' | 'swc';
javascriptEnabled?: boolean;
// TODO(jack): remove this for Nx 16
skipTypeField?: boolean;
generateExportsField?: boolean;
}
10 changes: 5 additions & 5 deletions packages/rollup/src/executors/rollup/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
"x-completion-glob": "tsconfig.*.json",
"x-priority": "important"
},
"allowJs": {
"type": "boolean",
"description": "Allow JavaScript files to be compiled.",
"default": false
},
"format": {
"type": "array",
"description": "List of module formats to output. Defaults to matching format from tsconfig (e.g. CJS for CommonJS, and ESM otherwise).",
Expand Down Expand Up @@ -141,11 +146,6 @@
"type": "boolean",
"description": "Generate package.json with 'exports' field. This field defines entry points in the package and is used by Node and the TypeScript compiler.",
"default": false
},
"skipTypeField": {
"type": "boolean",
"description": "Prevents 'type' field from being added to compiled package.json file. Only use this if you are having an issue with this field.",
"default": false
}
},
"required": ["tsConfig", "main", "outputPath"],
Expand Down