-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 default development configuration for React and Next…
….js apps
- Loading branch information
Showing
10 changed files
with
210 additions
and
4 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
43 changes: 43 additions & 0 deletions
43
packages/next/src/migrations/update-14-0-0/add-default-development-configurations.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,43 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { | ||
addProjectConfiguration, | ||
readProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
import update from './add-default-development-configurations'; | ||
|
||
describe('React default development configuration', () => { | ||
it('should add development configuration if it does not exist', async () => { | ||
const tree = createTreeWithEmptyWorkspace(2); | ||
addProjectConfiguration( | ||
tree, | ||
'example', | ||
{ | ||
root: 'apps/example', | ||
projectType: 'application', | ||
targets: { | ||
build: { | ||
executor: '@nrwl/next:build', | ||
configurations: {}, | ||
}, | ||
serve: { | ||
executor: '@nrwl/next:server', | ||
configurations: {}, | ||
}, | ||
}, | ||
}, | ||
true | ||
); | ||
|
||
await update(tree); | ||
|
||
const config = readProjectConfiguration(tree, 'example'); | ||
|
||
expect(config.targets.build.defaultConfiguration).toEqual('production'); | ||
expect(config.targets.build.configurations.development).toEqual({}); | ||
|
||
expect(config.targets.serve.defaultConfiguration).toEqual('development'); | ||
expect(config.targets.serve.configurations.development).toEqual({ | ||
buildTarget: `example:build:development`, | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/next/src/migrations/update-14-0-0/add-default-development-configurations.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,34 @@ | ||
import { | ||
formatFiles, | ||
getProjects, | ||
Tree, | ||
updateProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
|
||
export async function update(tree: Tree) { | ||
const projects = getProjects(tree); | ||
|
||
projects.forEach((config, name) => { | ||
let shouldUpdate = false; | ||
if (config.targets.build?.executor === '@nrwl/next:build') { | ||
shouldUpdate = true; | ||
config.targets.build.defaultConfiguration ??= 'production'; | ||
config.targets.build.configurations.development ??= {}; | ||
} | ||
|
||
if (config.targets.serve?.executor === '@nrwl/next:server') { | ||
shouldUpdate = true; | ||
config.targets.serve.defaultConfiguration ??= 'development'; | ||
config.targets.serve.configurations.development ??= { | ||
buildTarget: `${name}:build:development`, | ||
dev: true, | ||
}; | ||
} | ||
|
||
if (shouldUpdate) updateProjectConfiguration(tree, name, config); | ||
}); | ||
|
||
await formatFiles(tree); | ||
} | ||
|
||
export default update; |
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
48 changes: 48 additions & 0 deletions
48
packages/react/src/migrations/update-14-0-0/add-default-development-configurations.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,48 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { | ||
addProjectConfiguration, | ||
readProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
import update from './add-default-development-configurations'; | ||
|
||
describe('React default development configuration', () => { | ||
it('should add development configuration if it does not exist', async () => { | ||
const tree = createTreeWithEmptyWorkspace(2); | ||
addProjectConfiguration( | ||
tree, | ||
'example', | ||
{ | ||
root: 'apps/example', | ||
projectType: 'application', | ||
targets: { | ||
build: { | ||
executor: '@nrwl/web:webpack', | ||
configurations: {}, | ||
}, | ||
serve: { | ||
executor: '@nrwl/web:dev-server', | ||
configurations: {}, | ||
}, | ||
}, | ||
}, | ||
true | ||
); | ||
|
||
await update(tree); | ||
|
||
const config = readProjectConfiguration(tree, 'example'); | ||
|
||
expect(config.targets.build.defaultConfiguration).toEqual('production'); | ||
expect(config.targets.build.configurations.development).toEqual({ | ||
extractLicenses: false, | ||
optimization: false, | ||
sourceMap: true, | ||
vendorChunk: true, | ||
}); | ||
|
||
expect(config.targets.serve.defaultConfiguration).toEqual('development'); | ||
expect(config.targets.serve.configurations.development).toEqual({ | ||
buildTarget: `example:build:development`, | ||
}); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/react/src/migrations/update-14-0-0/add-default-development-configurations.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,38 @@ | ||
import { | ||
formatFiles, | ||
getProjects, | ||
Tree, | ||
updateProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
|
||
export async function update(tree: Tree) { | ||
const projects = getProjects(tree); | ||
|
||
projects.forEach((config, name) => { | ||
let shouldUpdate = false; | ||
if (config.targets.build?.executor === '@nrwl/web:webpack') { | ||
shouldUpdate = true; | ||
config.targets.build.defaultConfiguration ??= 'production'; | ||
config.targets.build.configurations.development ??= { | ||
extractLicenses: false, | ||
optimization: false, | ||
sourceMap: true, | ||
vendorChunk: true, | ||
}; | ||
} | ||
|
||
if (config.targets.serve?.executor === '@nrwl/web:dev-server') { | ||
shouldUpdate = true; | ||
config.targets.serve.defaultConfiguration ??= 'development'; | ||
config.targets.serve.configurations.development ??= { | ||
buildTarget: `${name}:build:development`, | ||
}; | ||
} | ||
|
||
if (shouldUpdate) updateProjectConfiguration(tree, name, config); | ||
}); | ||
|
||
await formatFiles(tree); | ||
} | ||
|
||
export default update; |