-
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(bundling): Add support to rollup for babelUpwardRootMode
- Loading branch information
1 parent
48d1c89
commit 8ea7b3c
Showing
16 changed files
with
213 additions
and
2 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
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
packages/expo/src/migrations/update-16-3-1-rename-babel/update-16-3-1-rename-babel.ts
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,18 @@ | ||
import { Tree, formatFiles, readProjectConfiguration } from '@nx/devkit'; | ||
import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; | ||
import { RollupExecutorOptions } from '@nx/rollup'; | ||
|
||
export default async function update(tree: Tree) { | ||
forEachExecutorOptions<RollupExecutorOptions>( | ||
tree, | ||
'@nx/rollup:rollup', | ||
(_, projectName) => { | ||
const root = readProjectConfiguration(tree, projectName).sourceRoot; | ||
const oldBabelPath = `${root}/babel.config.json`; | ||
if (tree.exists(oldBabelPath)) { | ||
tree.rename(oldBabelPath, `${root}/.babelrc`); | ||
} | ||
} | ||
); | ||
await formatFiles(tree); | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/expo/src/migrations/update-16-3-1-rename-babel/update-16-3-1-rename.babel.spec.ts
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,28 @@ | ||
import { Tree, addProjectConfiguration } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports'; | ||
import update from './update-16-3-1-rename-babel'; | ||
describe('rename babelConfig', () => { | ||
let tree: Tree; | ||
beforeEach(async () => { | ||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); | ||
addProjectConfiguration(tree, 'products', { | ||
root: 'libs/products', | ||
sourceRoot: 'libs/products/src', | ||
targets: { | ||
start: { | ||
executor: '@nx/rollup:rollup', | ||
options: {}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should rename babel.config.json to .babelrc', async () => { | ||
tree.write('libs/products/src/babel.config.json', `{}`); | ||
|
||
await update(tree); | ||
|
||
expect(tree.exists('libs/products/src/.babelrc')).toBeTruthy(); | ||
expect(tree.exists('libs/products/src/.babel.config.json')).toBeFalsy(); | ||
}); | ||
}); |
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
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
...react-native/src/migrations/update-16-3-1-rename-babel/update-16-3-1-rename-babel.spec.ts
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,28 @@ | ||
import { Tree, addProjectConfiguration } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports'; | ||
import update from './update-16-3-1-rename-babel'; | ||
describe('rename babelConfig', () => { | ||
let tree: Tree; | ||
beforeEach(async () => { | ||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); | ||
addProjectConfiguration(tree, 'products', { | ||
root: 'libs/products', | ||
sourceRoot: 'libs/products/src', | ||
targets: { | ||
start: { | ||
executor: '@nx/rollup:rollup', | ||
options: {}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should rename babel.config.json to .babelrc', async () => { | ||
tree.write('libs/products/src/babel.config.json', `{}`); | ||
|
||
await update(tree); | ||
|
||
expect(tree.exists('libs/products/src/.babelrc')).toBeTruthy(); | ||
expect(tree.exists('libs/products/src/.babel.config.json')).toBeFalsy(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
...ages/react-native/src/migrations/update-16-3-1-rename-babel/update-16-3-1-rename-babel.ts
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,18 @@ | ||
import { Tree, formatFiles, readProjectConfiguration } from '@nx/devkit'; | ||
import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; | ||
import { RollupExecutorOptions } from '@nx/rollup'; | ||
|
||
export default async function update(tree: Tree) { | ||
forEachExecutorOptions<RollupExecutorOptions>( | ||
tree, | ||
'@nx/rollup:rollup', | ||
(_, projectName) => { | ||
const root = readProjectConfiguration(tree, projectName).sourceRoot; | ||
const oldBabelPath = `${root}/babel.config.json`; | ||
if (tree.exists(oldBabelPath)) { | ||
tree.rename(oldBabelPath, `${root}/.babelrc`); | ||
} | ||
} | ||
); | ||
await formatFiles(tree); | ||
} |
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
58 changes: 58 additions & 0 deletions
58
...3-1-add-babel-upward-root-mode-flag/update-16-3-1-add-babel-upward-root-mode-flag.spec.ts
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,58 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import { | ||
addProjectConfiguration, | ||
readProjectConfiguration, | ||
Tree, | ||
} from '@nx/devkit'; | ||
import addBabelUpwardRootModeFlag from './update-16-3-1-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(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
...e-16-3-1-add-babel-upward-root-mode-flag/update-16-3-1-add-babel-upward-root-mode-flag.ts
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,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); | ||
} |