Skip to content

Commit

Permalink
feat(bundling): Add support to rollup for babelUpwardRootMode" (#17422)…
Browse files Browse the repository at this point in the history
…" (#17427)
  • Loading branch information
jaysoo authored Jun 5, 2023
1 parent 334ed07 commit bbb64f8
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 4 deletions.
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/expo/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join, normalize, sep } from 'path';
import { ChildProcess, fork } from 'child_process';

import { ensureNodeModulesSymlink } from '../../utils/ensure-node-modules-symlink';
import { copyBuildFile, unzipBuild } from '../download/download.impl';
import { unzipBuild } from '../download/download.impl';

import { ExpoEasBuildOptions } from './schema';
import { removeSync } from 'fs-extra';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "<%= rootTsConfigPath %>",
"compilerOptions": {
"jsx": "react-native",
"jsx": "react-jsx",
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "<%= rootTsConfigPath %>",
"compilerOptions": {
"jsx": "react-native",
"jsx": "react-jsx",
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
Expand Down
6 changes: 6 additions & 0 deletions packages/rollup/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"version": "16.0.0-beta.1",
"description": "Replace @nrwl/rollup with @nx/rollup",
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
},
"update-16-3-3-add-babel-upward-root-mode-flag": {
"cli": "nx",
"version": "16-3-3-beta.0",
"description": "Add babelUpwardRootMode if not already defined",
"implementation": "./src/migrations/update-16-3-3-add-babel-upward-root-mode-flag/update-16-3-3-add-babel-upward-root-mode-flag"
}
},
"packageJsonUpdates": {}
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-3-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);
}

1 comment on commit bbb64f8

@vercel
Copy link

@vercel vercel bot commented on bbb64f8 Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.