Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vite): add createNodesV2 function #26484

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
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",
],
},
},
},
},
}
],
]
`;
188 changes: 100 additions & 88 deletions packages/vite/src/plugins/__snapshots__/plugin.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,107 +1,119 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`@nx/vite/plugin not root project should create nodes 1`] = `
{
"projects": {
"my-app": {
"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": {
".": {
"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