<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> When Vite's tries to handle a `.ts` config file it builds it to JS with a `.timestamp-` suffix. These files are still picked up by Nx when they shouldn't as it's a temp file (https://github.com/vitejs/vite/issues/13267). ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Add these temp files to gitignore to prevent processing. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #28371
This commit is contained in:
parent
4b6c831a48
commit
5dbea2e16f
@ -1,13 +1,13 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`app generated files content - as-provided - my-app general application should add nuxt entries in .gitignore 1`] = `
|
||||
"
|
||||
# Nuxt dev/build outputs
|
||||
"# Nuxt dev/build outputs
|
||||
.output
|
||||
.data
|
||||
.nuxt
|
||||
.nitro
|
||||
.cache"
|
||||
.cache
|
||||
**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*"
|
||||
`;
|
||||
|
||||
exports[`app generated files content - as-provided - my-app general application should add the nuxt and vitest plugins 1`] = `
|
||||
@ -364,13 +364,13 @@ export default defineNuxtConfig({
|
||||
`;
|
||||
|
||||
exports[`app generated files content - as-provided - myApp general application should add nuxt entries in .gitignore 1`] = `
|
||||
"
|
||||
# Nuxt dev/build outputs
|
||||
"# Nuxt dev/build outputs
|
||||
.output
|
||||
.data
|
||||
.nuxt
|
||||
.nitro
|
||||
.cache"
|
||||
.cache
|
||||
**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*"
|
||||
`;
|
||||
|
||||
exports[`app generated files content - as-provided - myApp general application should add the nuxt and vitest plugins 1`] = `
|
||||
|
||||
@ -127,4 +127,20 @@ describe('@nx/vite:init', () => {
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
||||
it(`should not add multiple instances of the same vite temp file glob to gitignore`, async () => {
|
||||
// ARRANGE
|
||||
tree.write(
|
||||
'.gitignore',
|
||||
'**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*'
|
||||
);
|
||||
|
||||
// ACT
|
||||
await initGenerator(tree, {});
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(
|
||||
`"**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*"`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -13,6 +13,7 @@ import { setupPathsPlugin } from '../setup-paths-plugin/setup-paths-plugin';
|
||||
import { createNodesV2 } from '../../plugins/plugin';
|
||||
import { InitGeneratorSchema } from './schema';
|
||||
import { checkDependenciesInstalled, moveToDevDependencies } from './lib/utils';
|
||||
import { addViteTempFilesToGitIgnore } from '../../utils/add-vite-temp-files-to-gitignore';
|
||||
|
||||
export function updateNxJsonSettings(tree: Tree) {
|
||||
const nxJson = readNxJson(tree);
|
||||
@ -83,6 +84,7 @@ export async function initGeneratorInternal(
|
||||
}
|
||||
|
||||
updateNxJsonSettings(tree);
|
||||
addViteTempFilesToGitIgnore(tree);
|
||||
|
||||
if (schema.setupPathsPlugin) {
|
||||
await setupPathsPlugin(tree, { skipFormat: true });
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||
import addViteTempFilesToGitIgnore from './add-vite-temp-files-to-git-ignore';
|
||||
|
||||
describe('addViteTempFilesToGitIgnore', () => {
|
||||
it('should update an existing .gitignore file to add the glob correctly', () => {
|
||||
// ARRANGE
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('.gitignore', '.idea');
|
||||
|
||||
// ACT
|
||||
addViteTempFilesToGitIgnore(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(`
|
||||
".idea
|
||||
**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*"
|
||||
`);
|
||||
});
|
||||
|
||||
it('should write a new .gitignore file to add the glob correctly', () => {
|
||||
// ARRANGE
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.delete('.gitignore');
|
||||
|
||||
// ACT
|
||||
addViteTempFilesToGitIgnore(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(
|
||||
`"**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*"`
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,6 @@
|
||||
import { Tree } from '@nx/devkit';
|
||||
import { addViteTempFilesToGitIgnore as _addViteTempFilesToGitIgnore } from '../../utils/add-vite-temp-files-to-gitignore';
|
||||
|
||||
export default function addViteTempFilesToGitIgnore(tree: Tree) {
|
||||
_addViteTempFilesToGitIgnore(tree);
|
||||
}
|
||||
16
packages/vite/src/utils/add-vite-temp-files-to-gitignore.ts
Normal file
16
packages/vite/src/utils/add-vite-temp-files-to-gitignore.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { stripIndents, Tree } from '@nx/devkit';
|
||||
|
||||
export function addViteTempFilesToGitIgnore(tree: Tree) {
|
||||
let newGitIgnoreContents = `**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*`;
|
||||
if (tree.exists('.gitignore')) {
|
||||
const gitIgnoreContents = tree.read('.gitignore', 'utf-8');
|
||||
if (!gitIgnoreContents.includes(newGitIgnoreContents)) {
|
||||
newGitIgnoreContents = stripIndents`${gitIgnoreContents}
|
||||
${newGitIgnoreContents}`;
|
||||
|
||||
tree.write('.gitignore', newGitIgnoreContents);
|
||||
}
|
||||
} else {
|
||||
tree.write('.gitignore', newGitIgnoreContents);
|
||||
}
|
||||
}
|
||||
@ -346,6 +346,7 @@ exports[`application generator should set up project correctly with given option
|
||||
[
|
||||
".eslintignore",
|
||||
".eslintrc.json",
|
||||
".gitignore",
|
||||
".prettierignore",
|
||||
".prettierrc",
|
||||
".vscode/extensions.json",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user