-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nextjs): set development outputPath to a different one from produ…
- Loading branch information
Showing
4 changed files
with
102 additions
and
1 deletion.
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
68 changes: 68 additions & 0 deletions
68
packages/next/src/migrations/update-14-4-3/add-dev-output-path.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,68 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { | ||
addProjectConfiguration, | ||
readProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
import update from './add-dev-output-path'; | ||
|
||
describe('React default development configuration', () => { | ||
it('should add output path if it does not alreayd exist', async () => { | ||
const tree = createTreeWithEmptyWorkspace(2); | ||
addProjectConfiguration( | ||
tree, | ||
'example', | ||
{ | ||
root: 'apps/example', | ||
sourceRoot: 'apps/example', | ||
projectType: 'application', | ||
targets: { | ||
build: { | ||
executor: '@nrwl/next:build', | ||
configurations: { | ||
development: {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
true | ||
); | ||
|
||
await update(tree); | ||
|
||
const config = readProjectConfiguration(tree, 'example'); | ||
|
||
expect(config.targets.build.configurations.development.outputPath).toEqual( | ||
'tmp/apps/example' | ||
); | ||
}); | ||
|
||
it('should skip update if outputPath already exists for development', async () => { | ||
const tree = createTreeWithEmptyWorkspace(2); | ||
addProjectConfiguration( | ||
tree, | ||
'example', | ||
{ | ||
root: 'apps/example', | ||
sourceRoot: 'apps/example', | ||
projectType: 'application', | ||
targets: { | ||
build: { | ||
executor: '@nrwl/next:build', | ||
configurations: { | ||
development: { outputPath: '/tmp/some/custom/path' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
true | ||
); | ||
|
||
await update(tree); | ||
|
||
const config = readProjectConfiguration(tree, 'example'); | ||
|
||
expect(config.targets.build.configurations.development.outputPath).toEqual( | ||
'/tmp/some/custom/path' | ||
); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/next/src/migrations/update-14-4-3/add-dev-output-path.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,25 @@ | ||
import { | ||
formatFiles, | ||
getProjects, | ||
joinPathFragments, | ||
Tree, | ||
updateProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
|
||
export async function update(tree: Tree) { | ||
const projects = getProjects(tree); | ||
|
||
projects.forEach((config, name) => { | ||
if (config.targets?.build?.executor === '@nrwl/next:build') { | ||
config.targets.build.configurations ??= {}; | ||
config.targets.build.configurations.development ??= {}; | ||
config.targets.build.configurations.development.outputPath ??= | ||
joinPathFragments('tmp', config.sourceRoot); | ||
updateProjectConfiguration(tree, name, config); | ||
} | ||
}); | ||
|
||
await formatFiles(tree); | ||
} | ||
|
||
export default update; |