-
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(core): add migration to disable adding plugins automatically in …
…existing workspaces
- Loading branch information
1 parent
7c231e3
commit b17f0a7
Showing
4 changed files
with
84 additions
and
10 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
29 changes: 29 additions & 0 deletions
29
packages/nx/src/migrations/update-18-0-0/disable-crysal-for-existing-workspaces.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,29 @@ | ||
import { createTree } from '../../generators/testing-utils/create-tree'; | ||
import migrate from './disable-crystal-for-existing-workspaces'; | ||
|
||
describe('disable crystal for existing workspaces', () => { | ||
it("should create a .env if it doesn't exist", () => { | ||
const tree = createTree(); | ||
migrate(tree); | ||
expect(tree.read('.env', 'utf-8')).toMatchInlineSnapshot(` | ||
"# Nx 18 enables using plugins to infer targets by default | ||
# This is disabled for existing workspaces to maintain compatibility | ||
# For more info, see: https://nx.dev/concepts/inferred-tasks | ||
NX_ADD_PLUGINS=false" | ||
`); | ||
}); | ||
|
||
it('should update an existing .env', () => { | ||
const tree = createTree(); | ||
tree.write('.env', 'FOO=bar'); | ||
migrate(tree); | ||
expect(tree.read('.env', 'utf-8')).toMatchInlineSnapshot(` | ||
"FOO=bar | ||
# Nx 18 enables using plugins to infer targets by default | ||
# This is disabled for existing workspaces to maintain compatibility | ||
# For more info, see: https://nx.dev/concepts/inferred-tasks | ||
NX_ADD_PLUGINS=false" | ||
`); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
packages/nx/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.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,33 @@ | ||
import { Tree } from '../../generators/tree'; | ||
import { logger } from '../../utils/logger'; | ||
import ignore from 'ignore'; | ||
|
||
export default function migrate(tree: Tree) { | ||
const ig = ignore(); | ||
try { | ||
ig.add(tree.read('.gitignore', 'utf-8')); | ||
if (ig.ignores('.env')) { | ||
logger.warn( | ||
'NX The NX_ADD_PLUGINS=false environment variable was added to your .env file for backwards compatibility. However, your .env is ignored by git. Other contributors should add this key to their .env file or ensure that the environment variable is true when generating code with Nx.' | ||
); | ||
} | ||
} catch {} | ||
|
||
if (!tree.exists('.env')) { | ||
tree.write('.env', ''); | ||
} | ||
|
||
const dotenv = tree.read('.env', 'utf-8'); | ||
const newDotenvContents = [ | ||
'# Nx 18 enables using plugins to infer targets by default', | ||
'# This is disabled for existing workspaces to maintain compatibility', | ||
'# For more info, see: https://nx.dev/concepts/inferred-tasks', | ||
'NX_ADD_PLUGINS=false', | ||
]; | ||
|
||
if (dotenv.length) { | ||
newDotenvContents.unshift(dotenv, ''); | ||
} | ||
|
||
tree.write('.env', newDotenvContents.join('\n')); | ||
} |