Skip to content

Commit

Permalink
feat(bundling): Add support to rollup for babelUpwardRootMode
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham committed May 30, 2023
1 parent 911f753 commit 3b61080
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/generated/packages/rollup/executors/rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
"default": "babel",
"description": "Which compiler to use."
},
"babelUpwardRootMode": {
"type": "boolean",
"description": "Whether to set rootmode to upward. See https://babeljs.io/docs/en/options#rootmode",
"default": false
},
"javascriptEnabled": {
"type": "boolean",
"description": "Sets `javascriptEnabled` option for less loader",
Expand Down
2 changes: 1 addition & 1 deletion packages/rollup/src/executors/rollup/rollup.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export function createRollupOptions(
isModern: true,
},
cwd: join(context.root, sourceRoot),
rootMode: 'upward',
rootMode: options.babelUpwardRootMode ? 'upward' : undefined,
babelrc: true,
extensions: fileExtensions,
babelHelpers: 'bundled',
Expand Down
1 change: 1 addition & 0 deletions packages/rollup/src/executors/rollup/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export interface RollupExecutorOptions {
javascriptEnabled?: boolean;
generateExportsField?: boolean;
skipTypeCheck?: boolean;
babelUpwardRootMode?: boolean;
}
5 changes: 5 additions & 0 deletions packages/rollup/src/executors/rollup/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@
"default": "babel",
"description": "Which compiler to use."
},
"babelUpwardRootMode": {
"type": "boolean",
"description": "Whether to set rootmode to upward. See https://babeljs.io/docs/en/options#rootmode",
"default": false
},
"javascriptEnabled": {
"type": "boolean",
"description": "Sets `javascriptEnabled` option for less loader",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import {
addProjectConfiguration,
readProjectConfiguration,
Tree,
} from '@nx/devkit';
import addBabelUpwardRootModeFlag from './update-16-3-0-add-babel-upward-root-mode-flag';

describe('16.3.0 migration (add babelUpwardRootMode flag)', () => {
let tree: Tree;

beforeEach(async () => {
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
});

it('should add the babelUpwardRootMode flag to rollup projects', async () => {
addProjectConfiguration(tree, 'app1', {
root: 'apps/app1',
targets: {
build: {
executor: '@nx/rollup:rollup',
options: {},
},
},
});
addProjectConfiguration(tree, 'app2', {
root: 'apps/app2',
targets: {
build: {
executor: '@nx/rollup:rollup',
options: {
babelUpwardRootMode: false,
},
},
},
});

addProjectConfiguration(tree, 'app3', {
root: 'apps/app3',
targets: {
build: {
executor: '@nx/esbuild:esbuild',
options: {},
},
},
});

await addBabelUpwardRootModeFlag(tree);

const app1 = readProjectConfiguration(tree, 'app1');
const app2 = readProjectConfiguration(tree, 'app2');
const app3 = readProjectConfiguration(tree, 'app3');

expect(app1.targets['build'].options.babelUpwardRootMode).toBeTruthy();
expect(app2.targets['build'].options.babelUpwardRootMode).toBeFalsy();
expect(app3.targets['build'].options.babelUpwardRootMode).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
formatFiles,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nx/devkit';
import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils';
import { RollupExecutorOptions } from '../../executors/rollup/schema';

export default async function (tree: Tree) {
forEachExecutorOptions<RollupExecutorOptions>(
tree,
'@nx/rollup:rollup',
(
options: RollupExecutorOptions,
projectName,
targetName,
_configurationName
) => {
if (options.babelUpwardRootMode !== undefined) {
return;
}

const projectConfiguration = readProjectConfiguration(tree, projectName);
projectConfiguration.targets[targetName].options.babelUpwardRootMode =
true;
updateProjectConfiguration(tree, projectName, projectConfiguration);
}
);

await formatFiles(tree);
}

0 comments on commit 3b61080

Please sign in to comment.