Skip to content

Commit

Permalink
feat(vite): add CreateNodesV2 function
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Jun 10, 2024
1 parent 6db45e2 commit a7acc1d
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 162 deletions.
1 change: 1 addition & 0 deletions packages/vite/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {
createNodes,
createNodesV2,
VitePluginOptions,
createDependencies,
} from './src/plugins/plugin';
56 changes: 31 additions & 25 deletions packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`@nx/vite/plugin root project should create nodes 1`] = `
{
"projects": {
".": {
"root": ".",
"targets": {
"test": {
"cache": true,
"command": "vitest",
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"vitest",
[
[
"vitest.config.ts",
{
"projects": {
".": {
"metadata": {},
"root": ".",
"targets": {
"test": {
"cache": true,
"command": "vitest",
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"vitest",
],
},
{
"env": "CI",
},
],
"options": {
"cwd": ".",
},
"outputs": [
"{projectRoot}/coverage",
],
},
{
"env": "CI",
},
],
"options": {
"cwd": ".",
},
"outputs": [
"{projectRoot}/coverage",
],
},
},
},
},
}
],
]
`;
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`@nx/vite/plugin with test node root project should create nodes - with test too 1`] = `
{
"projects": {
".": {
"root": ".",
"targets": {
"test": {
"cache": true,
"command": "vitest",
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"vitest",
[
[
"vite.config.ts",
{
"projects": {
".": {
"metadata": {},
"root": ".",
"targets": {
"test": {
"cache": true,
"command": "vitest",
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"vitest",
],
},
{
"env": "CI",
},
],
"options": {
"cwd": ".",
},
"outputs": [
"{projectRoot}/coverage",
],
},
{
"env": "CI",
},
],
"options": {
"cwd": ".",
},
"outputs": [
"{projectRoot}/coverage",
],
},
},
},
},
}
],
]
`;
190 changes: 100 additions & 90 deletions packages/vite/src/plugins/__snapshots__/plugin.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,109 +1,119 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`@nx/vite/plugin not root project should create nodes 1`] = `
{
"projects": {
"my-app": {
"metadata": {},
"root": "my-app",
"targets": {
"build-something": {
"cache": true,
"command": "vite build",
"dependsOn": [
"^build-something",
],
"inputs": [
"production",
"^production",
{
"externalDependencies": [
"vite",
[
[
"my-app/vite.config.ts",
{
"projects": {
"my-app": {
"metadata": {},
"root": "my-app",
"targets": {
"build-something": {
"cache": true,
"command": "vite build",
"dependsOn": [
"^build-something",
],
"inputs": [
"production",
"^production",
{
"externalDependencies": [
"vite",
],
},
],
"options": {
"cwd": "my-app",
},
"outputs": [
"{workspaceRoot}/dist/{projectRoot}",
],
},
],
"options": {
"cwd": "my-app",
},
"outputs": [
"{workspaceRoot}/dist/{projectRoot}",
],
},
"my-serve": {
"command": "vite serve",
"options": {
"cwd": "my-app",
},
},
"preview-site": {
"command": "vite preview",
"options": {
"cwd": "my-app",
},
},
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build-something",
"spa": true,
"my-serve": {
"command": "vite serve",
"options": {
"cwd": "my-app",
},
},
"preview-site": {
"command": "vite preview",
"options": {
"cwd": "my-app",
},
},
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build-something",
"spa": true,
},
},
},
},
},
},
},
}
],
]
`;

exports[`@nx/vite/plugin root project should create nodes 1`] = `
{
"projects": {
".": {
"metadata": {},
"root": ".",
"targets": {
"build": {
"cache": true,
"command": "vite build",
"dependsOn": [
"^build",
],
"inputs": [
"production",
"^production",
{
"externalDependencies": [
"vite",
[
[
"vite.config.ts",
{
"projects": {
".": {
"metadata": {},
"root": ".",
"targets": {
"build": {
"cache": true,
"command": "vite build",
"dependsOn": [
"^build",
],
"inputs": [
"production",
"^production",
{
"externalDependencies": [
"vite",
],
},
],
"options": {
"cwd": ".",
},
"outputs": [
"{projectRoot}/dist",
],
},
],
"options": {
"cwd": ".",
},
"outputs": [
"{projectRoot}/dist",
],
},
"preview": {
"command": "vite preview",
"options": {
"cwd": ".",
},
},
"serve": {
"command": "vite serve",
"options": {
"cwd": ".",
},
},
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build",
"spa": true,
"preview": {
"command": "vite preview",
"options": {
"cwd": ".",
},
},
"serve": {
"command": "vite serve",
"options": {
"cwd": ".",
},
},
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build",
"spa": true,
},
},
},
},
},
},
},
}
],
]
`;
7 changes: 4 additions & 3 deletions packages/vite/src/plugins/plugin-vitest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreateNodesContext } from '@nx/devkit';
import { createNodes } from './plugin';
import { createNodesV2 } from './plugin';

jest.mock('vite', () => ({
resolveConfig: jest.fn().mockImplementation(() => {
Expand All @@ -22,7 +22,7 @@ jest.mock('../utils/executor-utils', () => ({
}));

describe('@nx/vite/plugin', () => {
let createNodesFunction = createNodes[1];
let createNodesFunction = createNodesV2[1];
let context: CreateNodesContext;
describe('root project', () => {
beforeEach(async () => {
Expand All @@ -35,6 +35,7 @@ describe('@nx/vite/plugin', () => {
},
},
workspaceRoot: '',
configFiles: [],
};
});

Expand All @@ -44,7 +45,7 @@ describe('@nx/vite/plugin', () => {

it('should create nodes', async () => {
const nodes = await createNodesFunction(
'vitest.config.ts',
['vitest.config.ts'],
{
testTargetName: 'test',
},
Expand Down
Loading

0 comments on commit a7acc1d

Please sign in to comment.