- feat(vite): add convert-to-inferred generator for migrating to inference - feat(vite): add build postTargetTransformer - feat(vite): add serve, preview, test postTargetTransformer - feat(vite): convert-to-inferred should clean up inputs and outputs - docs(vite): add convert-to-inferred - feat(vite): update outDir correctly <!-- 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` --> ## Current Behavior <!-- This is the behavior we have today --> There is currently no generator that can migrate projects that use `@nx/vite:*` executors to use Inference plugins. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Add `@nx/vite:convert-to-inferred` generator ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # --------- Co-authored-by: Jack Hsu <jack.hsu@gmail.com>
151 lines
4.0 KiB
TypeScript
151 lines
4.0 KiB
TypeScript
import { CreateNodesContext } from '@nx/devkit';
|
|
import { createNodes, createNodesV2 } from './plugin';
|
|
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';
|
|
import { loadViteDynamicImport } from '../utils/executor-utils';
|
|
|
|
jest.mock('../utils/executor-utils', () => ({
|
|
loadViteDynamicImport: jest.fn().mockResolvedValue({
|
|
resolveConfig: jest.fn().mockResolvedValue({}),
|
|
}),
|
|
}));
|
|
|
|
describe('@nx/vite/plugin', () => {
|
|
let createNodesFunction = createNodesV2[1];
|
|
let context: CreateNodesContext;
|
|
|
|
describe('root project', () => {
|
|
let tempFs: TempFs;
|
|
beforeEach(async () => {
|
|
tempFs = new TempFs('vite-plugin-tests');
|
|
context = {
|
|
configFiles: [],
|
|
nxJsonConfiguration: {
|
|
// These defaults should be overridden by plugin
|
|
targetDefaults: {
|
|
build: {
|
|
cache: false,
|
|
inputs: ['foo', '^foo'],
|
|
},
|
|
},
|
|
namedInputs: {
|
|
default: ['{projectRoot}/**/*'],
|
|
production: ['!{projectRoot}/**/*.spec.ts'],
|
|
},
|
|
},
|
|
workspaceRoot: tempFs.tempDir,
|
|
};
|
|
tempFs.createFileSync('vite.config.ts', '');
|
|
tempFs.createFileSync('index.html', '');
|
|
tempFs.createFileSync('package.json', '');
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.resetModules();
|
|
});
|
|
|
|
it('should create nodes', async () => {
|
|
const nodes = await createNodesFunction(
|
|
['vite.config.ts'],
|
|
{
|
|
buildTargetName: 'build',
|
|
serveTargetName: 'serve',
|
|
previewTargetName: 'preview',
|
|
testTargetName: 'test',
|
|
serveStaticTargetName: 'serve-static',
|
|
},
|
|
context
|
|
);
|
|
|
|
expect(nodes).toMatchSnapshot();
|
|
});
|
|
});
|
|
|
|
describe('not root project', () => {
|
|
let tempFs: TempFs;
|
|
beforeEach(() => {
|
|
tempFs = new TempFs('test');
|
|
context = {
|
|
configFiles: [],
|
|
nxJsonConfiguration: {
|
|
namedInputs: {
|
|
default: ['{projectRoot}/**/*'],
|
|
production: ['!{projectRoot}/**/*.spec.ts'],
|
|
},
|
|
},
|
|
workspaceRoot: tempFs.tempDir,
|
|
};
|
|
|
|
tempFs.createFileSync(
|
|
'my-app/project.json',
|
|
JSON.stringify({ name: 'my-app' })
|
|
);
|
|
tempFs.createFileSync('my-app/vite.config.ts', '');
|
|
tempFs.createFileSync('my-app/index.html', '');
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.resetModules();
|
|
});
|
|
|
|
it('should create nodes', async () => {
|
|
const nodes = await createNodesFunction(
|
|
['my-app/vite.config.ts'],
|
|
{
|
|
buildTargetName: 'build-something',
|
|
serveTargetName: 'my-serve',
|
|
previewTargetName: 'preview-site',
|
|
testTargetName: 'vitest',
|
|
serveStaticTargetName: 'serve-static',
|
|
},
|
|
context
|
|
);
|
|
|
|
expect(nodes).toMatchSnapshot();
|
|
});
|
|
});
|
|
|
|
describe('Library mode', () => {
|
|
it('should exclude serve and preview targets when vite.config.ts is in library mode', async () => {
|
|
const tempFs = new TempFs('test');
|
|
(loadViteDynamicImport as jest.Mock).mockResolvedValue({
|
|
resolveConfig: jest.fn().mockResolvedValue({
|
|
build: {
|
|
lib: {
|
|
entry: 'index.ts',
|
|
name: 'my-lib',
|
|
},
|
|
},
|
|
}),
|
|
}),
|
|
(context = {
|
|
configFiles: [],
|
|
nxJsonConfiguration: {
|
|
namedInputs: {
|
|
default: ['{projectRoot}/**/*'],
|
|
production: ['!{projectRoot}/**/*.spec.ts'],
|
|
},
|
|
},
|
|
workspaceRoot: tempFs.tempDir,
|
|
});
|
|
tempFs.createFileSync(
|
|
'my-lib/project.json',
|
|
JSON.stringify({ name: 'my-lib' })
|
|
);
|
|
tempFs.createFileSync('my-lib/vite.config.ts', '');
|
|
|
|
const nodes = await createNodesFunction(
|
|
['my-lib/vite.config.ts'],
|
|
{
|
|
buildTargetName: 'build',
|
|
serveTargetName: 'serve',
|
|
},
|
|
context
|
|
);
|
|
|
|
expect(nodes).toMatchSnapshot();
|
|
|
|
jest.resetModules();
|
|
});
|
|
});
|
|
});
|