@nx/remix 19.7.0-beta.3 → 19.7.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/remix",
3
- "version": "19.7.0-beta.3",
3
+ "version": "19.7.0-beta.4",
4
4
  "description": "The Remix plugin for Nx contains executors and generators for managing Remix applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Vitest, Jest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, routes, loaders, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,12 +29,12 @@
29
29
  "migrations": "./migrations.json"
30
30
  },
31
31
  "dependencies": {
32
- "@nx/devkit": "19.7.0-beta.3",
33
- "@nx/js": "19.7.0-beta.3",
34
- "@nx/react": "19.7.0-beta.3",
32
+ "@nx/devkit": "19.7.0-beta.4",
33
+ "@nx/js": "19.7.0-beta.4",
34
+ "@nx/react": "19.7.0-beta.4",
35
35
  "tslib": "^2.3.1",
36
36
  "@phenomnomnominal/tsquery": "~5.0.1",
37
- "@nrwl/remix": "19.7.0-beta.3"
37
+ "@nrwl/remix": "19.7.0-beta.4"
38
38
  },
39
39
  "peerDependencies": {},
40
40
  "publishConfig": {
package/plugin.d.ts CHANGED
@@ -1 +1 @@
1
- export { createNodes, createDependencies, RemixPluginOptions, } from './src/plugins/plugin';
1
+ export { createNodes, createNodesV2, createDependencies, RemixPluginOptions, } from './src/plugins/plugin';
package/plugin.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDependencies = exports.createNodes = void 0;
3
+ exports.createDependencies = exports.createNodesV2 = exports.createNodes = void 0;
4
4
  var plugin_1 = require("./src/plugins/plugin");
5
5
  Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
6
+ Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
6
7
  Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return plugin_1.createDependencies; } });
@@ -25,7 +25,7 @@ async function remixInitGeneratorInternal(tree, options) {
25
25
  nxJson.useInferencePlugins !== false;
26
26
  options.addPlugin ??= addPluginDefault;
27
27
  if (options.addPlugin) {
28
- await (0, add_plugin_1.addPluginV1)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/remix/plugin', plugin_1.createNodes, {
28
+ await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/remix/plugin', plugin_1.createNodesV2, {
29
29
  startTargetName: ['start', 'remix:start', 'remix-start'],
30
30
  buildTargetName: ['build', 'remix:build', 'remix-build'],
31
31
  devTargetName: ['dev', 'remix:dev', 'remix-dev'],
@@ -34,6 +34,11 @@ async function remixInitGeneratorInternal(tree, options) {
34
34
  'remix:typecheck',
35
35
  'remix-typecheck',
36
36
  ],
37
+ serveStaticTargetName: [
38
+ 'serve-static',
39
+ 'vite:serve-static',
40
+ 'vite-serve-static',
41
+ ],
37
42
  }, options.updatePackageScripts);
38
43
  }
39
44
  if (!options.skipFormat) {
@@ -1,169 +1,359 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`@nx/remix/plugin non-root project should create nodes 1`] = `
4
- {
5
- "projects": {
6
- "my-app": {
7
- "root": "my-app",
8
- "targets": {
9
- "build": {
10
- "cache": true,
11
- "command": "remix build",
12
- "dependsOn": [
13
- "^build",
14
- ],
15
- "inputs": [
16
- "production",
17
- "^production",
18
- {
19
- "externalDependencies": [
20
- "@remix-run/dev",
21
- ],
22
- },
23
- ],
24
- "options": {
25
- "cwd": "my-app",
26
- },
27
- "outputs": [
28
- "{workspaceRoot}/my-app/build",
29
- "{workspaceRoot}/my-app/public/build",
30
- ],
31
- },
32
- "dev": {
33
- "command": "remix dev --manual",
34
- "options": {
35
- "cwd": "my-app",
36
- },
37
- },
38
- "serve-static": {
39
- "command": "remix-serve build/index.js",
40
- "dependsOn": [
41
- "build",
42
- ],
43
- "options": {
44
- "cwd": "my-app",
45
- },
46
- },
47
- "start": {
48
- "command": "remix-serve build/index.js",
49
- "dependsOn": [
50
- "build",
51
- ],
52
- "options": {
53
- "cwd": "my-app",
54
- },
55
- },
56
- "static-serve": {
57
- "command": "remix-serve build/index.js",
58
- "dependsOn": [
59
- "build",
60
- ],
61
- "options": {
62
- "cwd": "my-app",
63
- },
64
- },
65
- "tsc": {
66
- "cache": true,
67
- "command": "tsc",
68
- "inputs": [
69
- "production",
70
- "^production",
71
- {
72
- "externalDependencies": [
73
- "typescript",
74
- ],
75
- },
76
- ],
77
- "options": {
78
- "cwd": "my-app",
3
+ exports[`@nx/remix/plugin Remix Classic Compiler non-root project should create nodes 1`] = `
4
+ [
5
+ [
6
+ "my-app/remix.config.cjs",
7
+ {
8
+ "projects": {
9
+ "my-app": {
10
+ "metadata": {},
11
+ "root": "my-app",
12
+ "targets": {
13
+ "build": {
14
+ "cache": true,
15
+ "command": "remix build",
16
+ "dependsOn": [
17
+ "^build",
18
+ ],
19
+ "inputs": [
20
+ "production",
21
+ "^production",
22
+ {
23
+ "externalDependencies": [
24
+ "@remix-run/dev",
25
+ ],
26
+ },
27
+ ],
28
+ "options": {
29
+ "cwd": "my-app",
30
+ },
31
+ "outputs": [
32
+ "{workspaceRoot}/my-app/build",
33
+ "{workspaceRoot}/my-app/public/build",
34
+ ],
35
+ },
36
+ "dev": {
37
+ "command": "remix dev --manual",
38
+ "options": {
39
+ "cwd": "my-app",
40
+ },
41
+ },
42
+ "serve-static": {
43
+ "command": "remix-serve build/index.js",
44
+ "dependsOn": [
45
+ "build",
46
+ ],
47
+ "options": {
48
+ "cwd": "my-app",
49
+ },
50
+ },
51
+ "start": {
52
+ "command": "remix-serve build/index.js",
53
+ "dependsOn": [
54
+ "build",
55
+ ],
56
+ "options": {
57
+ "cwd": "my-app",
58
+ },
59
+ },
60
+ "static-serve": {
61
+ "command": "remix-serve build/index.js",
62
+ "dependsOn": [
63
+ "build",
64
+ ],
65
+ "options": {
66
+ "cwd": "my-app",
67
+ },
68
+ },
69
+ "tsc": {
70
+ "cache": true,
71
+ "command": "tsc",
72
+ "inputs": [
73
+ "production",
74
+ "^production",
75
+ {
76
+ "externalDependencies": [
77
+ "typescript",
78
+ ],
79
+ },
80
+ ],
81
+ "options": {
82
+ "cwd": "my-app",
83
+ },
84
+ },
79
85
  },
80
86
  },
81
87
  },
82
88
  },
83
- },
84
- }
89
+ ],
90
+ ]
85
91
  `;
86
92
 
87
- exports[`@nx/remix/plugin root project should create nodes 1`] = `
88
- {
89
- "projects": {
90
- ".": {
91
- "root": ".",
92
- "targets": {
93
- "build": {
94
- "cache": true,
95
- "command": "remix build",
96
- "dependsOn": [
97
- "^build",
98
- ],
99
- "inputs": [
100
- "production",
101
- "^production",
102
- {
103
- "externalDependencies": [
104
- "@remix-run/dev",
105
- ],
106
- },
107
- ],
108
- "options": {
109
- "cwd": ".",
110
- },
111
- "outputs": [
112
- "{workspaceRoot}/build",
113
- "{workspaceRoot}/public/build",
114
- ],
115
- },
116
- "dev": {
117
- "command": "remix dev --manual",
118
- "options": {
119
- "cwd": ".",
120
- },
121
- },
122
- "serve-static": {
123
- "command": "remix-serve build/index.js",
124
- "dependsOn": [
125
- "build",
126
- ],
127
- "options": {
128
- "cwd": ".",
129
- },
130
- },
131
- "start": {
132
- "command": "remix-serve build/index.js",
133
- "dependsOn": [
134
- "build",
135
- ],
136
- "options": {
137
- "cwd": ".",
93
+ exports[`@nx/remix/plugin Remix Classic Compiler root project should create nodes 1`] = `
94
+ [
95
+ [
96
+ "remix.config.cjs",
97
+ {
98
+ "projects": {
99
+ ".": {
100
+ "metadata": {},
101
+ "root": ".",
102
+ "targets": {
103
+ "build": {
104
+ "cache": true,
105
+ "command": "remix build",
106
+ "dependsOn": [
107
+ "^build",
108
+ ],
109
+ "inputs": [
110
+ "production",
111
+ "^production",
112
+ {
113
+ "externalDependencies": [
114
+ "@remix-run/dev",
115
+ ],
116
+ },
117
+ ],
118
+ "options": {
119
+ "cwd": ".",
120
+ },
121
+ "outputs": [
122
+ "{workspaceRoot}/build",
123
+ "{workspaceRoot}/public/build",
124
+ ],
125
+ },
126
+ "dev": {
127
+ "command": "remix dev --manual",
128
+ "options": {
129
+ "cwd": ".",
130
+ },
131
+ },
132
+ "serve-static": {
133
+ "command": "remix-serve build/index.js",
134
+ "dependsOn": [
135
+ "build",
136
+ ],
137
+ "options": {
138
+ "cwd": ".",
139
+ },
140
+ },
141
+ "start": {
142
+ "command": "remix-serve build/index.js",
143
+ "dependsOn": [
144
+ "build",
145
+ ],
146
+ "options": {
147
+ "cwd": ".",
148
+ },
149
+ },
150
+ "static-serve": {
151
+ "command": "remix-serve build/index.js",
152
+ "dependsOn": [
153
+ "build",
154
+ ],
155
+ "options": {
156
+ "cwd": ".",
157
+ },
158
+ },
159
+ "typecheck": {
160
+ "cache": true,
161
+ "command": "tsc",
162
+ "inputs": [
163
+ "production",
164
+ "^production",
165
+ {
166
+ "externalDependencies": [
167
+ "typescript",
168
+ ],
169
+ },
170
+ ],
171
+ "options": {
172
+ "cwd": ".",
173
+ },
174
+ },
138
175
  },
139
176
  },
140
- "static-serve": {
141
- "command": "remix-serve build/index.js",
142
- "dependsOn": [
143
- "build",
144
- ],
145
- "options": {
146
- "cwd": ".",
177
+ },
178
+ },
179
+ ],
180
+ ]
181
+ `;
182
+
183
+ exports[`@nx/remix/plugin Remix Vite Compiler non-root project should create nodes 1`] = `
184
+ [
185
+ [
186
+ "my-app/vite.config.js",
187
+ {
188
+ "projects": {
189
+ "my-app": {
190
+ "metadata": {},
191
+ "root": "my-app",
192
+ "targets": {
193
+ "build": {
194
+ "cache": true,
195
+ "command": "remix vite:build",
196
+ "dependsOn": [
197
+ "^build",
198
+ ],
199
+ "inputs": [
200
+ "production",
201
+ "^production",
202
+ {
203
+ "externalDependencies": [
204
+ "@remix-run/dev",
205
+ ],
206
+ },
207
+ ],
208
+ "options": {
209
+ "cwd": "my-app",
210
+ },
211
+ "outputs": [
212
+ "{workspaceRoot}/my-app/build",
213
+ ],
214
+ },
215
+ "dev": {
216
+ "command": "remix vite:dev",
217
+ "options": {
218
+ "cwd": "my-app",
219
+ },
220
+ },
221
+ "serve-static": {
222
+ "command": "remix-serve build/server/index.js",
223
+ "dependsOn": [
224
+ "build",
225
+ ],
226
+ "options": {
227
+ "cwd": "my-app",
228
+ },
229
+ },
230
+ "start": {
231
+ "command": "remix-serve build/server/index.js",
232
+ "dependsOn": [
233
+ "build",
234
+ ],
235
+ "options": {
236
+ "cwd": "my-app",
237
+ },
238
+ },
239
+ "static-serve": {
240
+ "command": "remix-serve build/server/index.js",
241
+ "dependsOn": [
242
+ "build",
243
+ ],
244
+ "options": {
245
+ "cwd": "my-app",
246
+ },
247
+ },
248
+ "tsc": {
249
+ "cache": true,
250
+ "command": "tsc",
251
+ "inputs": [
252
+ "production",
253
+ "^production",
254
+ {
255
+ "externalDependencies": [
256
+ "typescript",
257
+ ],
258
+ },
259
+ ],
260
+ "options": {
261
+ "cwd": "my-app",
262
+ },
263
+ },
147
264
  },
148
265
  },
149
- "typecheck": {
150
- "cache": true,
151
- "command": "tsc",
152
- "inputs": [
153
- "production",
154
- "^production",
155
- {
156
- "externalDependencies": [
157
- "typescript",
158
- ],
159
- },
160
- ],
161
- "options": {
162
- "cwd": ".",
266
+ },
267
+ },
268
+ ],
269
+ ]
270
+ `;
271
+
272
+ exports[`@nx/remix/plugin Remix Vite Compiler root project should create nodes 1`] = `
273
+ [
274
+ [
275
+ "vite.config.js",
276
+ {
277
+ "projects": {
278
+ ".": {
279
+ "metadata": {},
280
+ "root": ".",
281
+ "targets": {
282
+ "build": {
283
+ "cache": true,
284
+ "command": "remix vite:build",
285
+ "dependsOn": [
286
+ "^build",
287
+ ],
288
+ "inputs": [
289
+ "production",
290
+ "^production",
291
+ {
292
+ "externalDependencies": [
293
+ "@remix-run/dev",
294
+ ],
295
+ },
296
+ ],
297
+ "options": {
298
+ "cwd": ".",
299
+ },
300
+ "outputs": [
301
+ "{workspaceRoot}/build",
302
+ ],
303
+ },
304
+ "dev": {
305
+ "command": "remix vite:dev",
306
+ "options": {
307
+ "cwd": ".",
308
+ },
309
+ },
310
+ "serve-static": {
311
+ "command": "remix-serve build/server/index.js",
312
+ "dependsOn": [
313
+ "build",
314
+ ],
315
+ "options": {
316
+ "cwd": ".",
317
+ },
318
+ },
319
+ "start": {
320
+ "command": "remix-serve build/server/index.js",
321
+ "dependsOn": [
322
+ "build",
323
+ ],
324
+ "options": {
325
+ "cwd": ".",
326
+ },
327
+ },
328
+ "static-serve": {
329
+ "command": "remix-serve build/server/index.js",
330
+ "dependsOn": [
331
+ "build",
332
+ ],
333
+ "options": {
334
+ "cwd": ".",
335
+ },
336
+ },
337
+ "typecheck": {
338
+ "cache": true,
339
+ "command": "tsc",
340
+ "inputs": [
341
+ "production",
342
+ "^production",
343
+ {
344
+ "externalDependencies": [
345
+ "typescript",
346
+ ],
347
+ },
348
+ ],
349
+ "options": {
350
+ "cwd": ".",
351
+ },
352
+ },
163
353
  },
164
354
  },
165
355
  },
166
356
  },
167
- },
168
- }
357
+ ],
358
+ ]
169
359
  `;
@@ -1,5 +1,4 @@
1
- import { type CreateDependencies, type CreateNodes } from '@nx/devkit';
2
- export declare const createDependencies: CreateDependencies;
1
+ import { type CreateDependencies, type CreateNodes, CreateNodesV2 } from '@nx/devkit';
3
2
  export interface RemixPluginOptions {
4
3
  buildTargetName?: string;
5
4
  devTargetName?: string;
@@ -11,4 +10,9 @@ export interface RemixPluginOptions {
11
10
  staticServeTargetName?: string;
12
11
  serveStaticTargetName?: string;
13
12
  }
13
+ /**
14
+ * @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
15
+ */
16
+ export declare const createDependencies: CreateDependencies;
17
+ export declare const createNodesV2: CreateNodesV2<RemixPluginOptions>;
14
18
  export declare const createNodes: CreateNodes<RemixPluginOptions>;
@@ -1,77 +1,108 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNodes = exports.createDependencies = void 0;
3
+ exports.createNodes = exports.createNodesV2 = exports.createDependencies = void 0;
4
4
  const cache_directory_1 = require("nx/src/utils/cache-directory");
5
+ const file_hasher_1 = require("nx/src/hasher/file-hasher");
5
6
  const devkit_1 = require("@nx/devkit");
6
7
  const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
7
8
  const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
9
+ const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
8
10
  const js_1 = require("@nx/js");
9
11
  const path_1 = require("path");
10
12
  const fs_1 = require("fs");
11
- const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
12
- const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'remix.hash');
13
- const targetsCache = readTargetsCache();
14
- function readTargetsCache() {
13
+ const executor_utils_1 = require("../utils/executor-utils");
14
+ function readTargetsCache(cachePath) {
15
15
  return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
16
16
  }
17
- function writeTargetsToCache() {
18
- const oldCache = readTargetsCache();
19
- (0, devkit_1.writeJsonFile)(cachePath, {
20
- ...oldCache,
21
- ...targetsCache,
22
- });
17
+ function writeTargetsToCache(cachePath, results) {
18
+ (0, devkit_1.writeJsonFile)(cachePath, results);
23
19
  }
20
+ /**
21
+ * @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
22
+ */
24
23
  const createDependencies = () => {
25
- writeTargetsToCache();
26
24
  return [];
27
25
  };
28
26
  exports.createDependencies = createDependencies;
27
+ const remixConfigGlob = '**/{remix,vite}.config.{js,cjs,mjs}';
28
+ exports.createNodesV2 = [
29
+ remixConfigGlob,
30
+ async (configFilePaths, options, context) => {
31
+ const optionsHash = (0, file_hasher_1.hashObject)(options);
32
+ const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `remix-${optionsHash}.hash`);
33
+ const targetsCache = readTargetsCache(cachePath);
34
+ try {
35
+ return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache), configFilePaths, options, context);
36
+ }
37
+ finally {
38
+ writeTargetsToCache(cachePath, targetsCache);
39
+ }
40
+ },
41
+ ];
29
42
  exports.createNodes = [
30
- '**/remix.config.{js,cjs,mjs}',
43
+ remixConfigGlob,
31
44
  async (configFilePath, options, context) => {
32
- const projectRoot = (0, path_1.dirname)(configFilePath);
33
- const fullyQualifiedProjectRoot = (0, path_1.join)(context.workspaceRoot, projectRoot);
34
- // Do not create a project if package.json and project.json isn't there
35
- const siblingFiles = (0, fs_1.readdirSync)(fullyQualifiedProjectRoot);
36
- if (!siblingFiles.includes('package.json') &&
37
- !siblingFiles.includes('project.json') &&
38
- !siblingFiles.includes('vite.config.ts') &&
39
- !siblingFiles.includes('vite.config.js')) {
40
- return {};
41
- }
42
- options = normalizeOptions(options);
43
- const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
44
- targetsCache[hash] ??= await buildRemixTargets(configFilePath, projectRoot, options, context, siblingFiles);
45
- return {
46
- projects: {
47
- [projectRoot]: {
48
- root: projectRoot,
49
- targets: targetsCache[hash],
50
- },
51
- },
52
- };
45
+ devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
46
+ return createNodesInternal(configFilePath, options, context, {});
53
47
  },
54
48
  ];
55
- async function buildRemixTargets(configFilePath, projectRoot, options, context, siblingFiles) {
49
+ async function createNodesInternal(configFilePath, options, context, targetsCache) {
50
+ const projectRoot = (0, path_1.dirname)(configFilePath);
51
+ const fullyQualifiedProjectRoot = (0, path_1.join)(context.workspaceRoot, projectRoot);
52
+ // Do not create a project if package.json and project.json isn't there
53
+ const siblingFiles = (0, fs_1.readdirSync)(fullyQualifiedProjectRoot);
54
+ if (!siblingFiles.includes('package.json') &&
55
+ !siblingFiles.includes('project.json')) {
56
+ return {};
57
+ }
58
+ options = normalizeOptions(options);
59
+ const remixCompiler = determineIsRemixVite(configFilePath, context.workspaceRoot);
60
+ if (remixCompiler === RemixCompiler.IsNotRemix) {
61
+ return {};
62
+ }
63
+ const hash = (await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
64
+ (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
65
+ ])) + configFilePath;
66
+ targetsCache[hash] ??= await buildRemixTargets(configFilePath, projectRoot, options, context, siblingFiles, remixCompiler);
67
+ const { targets, metadata } = targetsCache[hash];
68
+ const project = {
69
+ root: projectRoot,
70
+ targets,
71
+ metadata,
72
+ };
73
+ return {
74
+ projects: {
75
+ [projectRoot]: project,
76
+ },
77
+ };
78
+ }
79
+ async function buildRemixTargets(configFilePath, projectRoot, options, context, siblingFiles, remixCompiler) {
56
80
  const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
57
- const { buildDirectory, assetsBuildDirectory, serverBuildPath } = await getBuildPaths(configFilePath, context.workspaceRoot);
81
+ const { buildDirectory, assetsBuildDirectory, serverBuildPath } = await getBuildPaths(configFilePath, projectRoot, context.workspaceRoot, remixCompiler);
58
82
  const targets = {};
59
- targets[options.buildTargetName] = buildTarget(options.buildTargetName, projectRoot, buildDirectory, assetsBuildDirectory, namedInputs);
60
- targets[options.devTargetName] = devTarget(serverBuildPath, projectRoot);
61
- targets[options.startTargetName] = startTarget(projectRoot, serverBuildPath, options.buildTargetName);
83
+ targets[options.buildTargetName] = buildTarget(options.buildTargetName, projectRoot, buildDirectory, assetsBuildDirectory, namedInputs, remixCompiler);
84
+ targets[options.devTargetName] = devTarget(serverBuildPath, projectRoot, remixCompiler);
85
+ targets[options.startTargetName] = startTarget(projectRoot, serverBuildPath, options.buildTargetName, remixCompiler);
62
86
  // TODO(colum): Remove for Nx 21
63
- targets[options.staticServeTargetName] = startTarget(projectRoot, serverBuildPath, options.buildTargetName);
64
- targets[options.serveStaticTargetName] = startTarget(projectRoot, serverBuildPath, options.buildTargetName);
87
+ targets[options.staticServeTargetName] = startTarget(projectRoot, serverBuildPath, options.buildTargetName, remixCompiler);
88
+ targets[options.serveStaticTargetName] = startTarget(projectRoot, serverBuildPath, options.buildTargetName, remixCompiler);
65
89
  targets[options.typecheckTargetName] = typecheckTarget(projectRoot, namedInputs, siblingFiles);
66
- return targets;
90
+ return { targets, metadata: {} };
67
91
  }
68
- function buildTarget(buildTargetName, projectRoot, buildDirectory, assetsBuildDirectory, namedInputs) {
92
+ function buildTarget(buildTargetName, projectRoot, buildDirectory, assetsBuildDirectory, namedInputs, remixCompiler) {
69
93
  const serverBuildOutputPath = projectRoot === '.'
70
94
  ? (0, devkit_1.joinPathFragments)(`{workspaceRoot}`, buildDirectory)
71
95
  : (0, devkit_1.joinPathFragments)(`{workspaceRoot}`, projectRoot, buildDirectory);
72
96
  const assetsBuildOutputPath = projectRoot === '.'
73
97
  ? (0, devkit_1.joinPathFragments)(`{workspaceRoot}`, assetsBuildDirectory)
74
98
  : (0, devkit_1.joinPathFragments)(`{workspaceRoot}`, projectRoot, assetsBuildDirectory);
99
+ const outputs = remixCompiler === RemixCompiler.IsVte
100
+ ? [
101
+ projectRoot === '.'
102
+ ? (0, devkit_1.joinPathFragments)(`{workspaceRoot}`, buildDirectory)
103
+ : (0, devkit_1.joinPathFragments)(`{workspaceRoot}`, projectRoot, buildDirectory),
104
+ ]
105
+ : [serverBuildOutputPath, assetsBuildOutputPath];
75
106
  return {
76
107
  cache: true,
77
108
  dependsOn: [`^${buildTargetName}`],
@@ -81,21 +112,31 @@ function buildTarget(buildTargetName, projectRoot, buildDirectory, assetsBuildDi
81
112
  : ['default', '^default']),
82
113
  { externalDependencies: ['@remix-run/dev'] },
83
114
  ],
84
- outputs: [serverBuildOutputPath, assetsBuildOutputPath],
85
- command: 'remix build',
115
+ outputs,
116
+ command: remixCompiler === RemixCompiler.IsVte
117
+ ? 'remix vite:build'
118
+ : 'remix build',
86
119
  options: { cwd: projectRoot },
87
120
  };
88
121
  }
89
- function devTarget(serverBuildPath, projectRoot) {
122
+ function devTarget(serverBuildPath, projectRoot, remixCompiler) {
90
123
  return {
91
- command: 'remix dev --manual',
124
+ command: remixCompiler === RemixCompiler.IsVte
125
+ ? 'remix vite:dev'
126
+ : 'remix dev --manual',
92
127
  options: { cwd: projectRoot },
93
128
  };
94
129
  }
95
- function startTarget(projectRoot, serverBuildPath, buildTargetName) {
130
+ function startTarget(projectRoot, serverBuildPath, buildTargetName, remixCompiler) {
131
+ let serverPath = serverBuildPath;
132
+ if (remixCompiler === RemixCompiler.IsVte) {
133
+ if (serverBuildPath === 'build') {
134
+ serverPath = `${serverBuildPath}/server/index.js`;
135
+ }
136
+ }
96
137
  return {
97
138
  dependsOn: [buildTargetName],
98
- command: `remix-serve ${serverBuildPath}`,
139
+ command: `remix-serve ${serverPath}`,
99
140
  options: {
100
141
  cwd: projectRoot,
101
142
  },
@@ -118,14 +159,37 @@ function typecheckTarget(projectRoot, namedInputs, siblingFiles) {
118
159
  },
119
160
  };
120
161
  }
121
- async function getBuildPaths(configFilePath, workspaceRoot) {
162
+ async function getBuildPaths(configFilePath, projectRoot, workspaceRoot, remixCompiler) {
122
163
  const configPath = (0, path_1.join)(workspaceRoot, configFilePath);
123
- let appConfig = await (0, config_utils_1.loadConfigFile)(configPath);
124
- return {
125
- buildDirectory: 'build',
126
- serverBuildPath: appConfig.serverBuildPath ?? 'build/index.js',
127
- assetsBuildDirectory: appConfig.assetsBuildDirectory ?? 'public/build',
128
- };
164
+ if (remixCompiler === RemixCompiler.IsClassic) {
165
+ let appConfig = await (0, config_utils_1.loadConfigFile)(configPath);
166
+ return {
167
+ buildDirectory: 'build',
168
+ serverBuildPath: appConfig.serverBuildPath ?? 'build/index.js',
169
+ assetsBuildDirectory: appConfig.assetsBuildDirectory ?? 'public/build',
170
+ };
171
+ }
172
+ else {
173
+ // Workaround for the `build$3 is not a function` error that we sometimes see in agents.
174
+ // This should be removed later once we address the issue properly
175
+ try {
176
+ const importEsbuild = () => new Function('return import("esbuild")')();
177
+ await importEsbuild();
178
+ }
179
+ catch {
180
+ // do nothing
181
+ }
182
+ const { resolveConfig } = await (0, executor_utils_1.loadViteDynamicImport)();
183
+ const viteBuildConfig = await resolveConfig({
184
+ configFile: configPath,
185
+ mode: 'development',
186
+ }, 'build');
187
+ return {
188
+ buildDirectory: viteBuildConfig.build?.outDir ?? 'build',
189
+ serverBuildPath: viteBuildConfig.build?.outDir ?? 'build',
190
+ assetsBuildDirectory: 'build/client',
191
+ };
192
+ }
129
193
  }
130
194
  function normalizeOptions(options) {
131
195
  options ??= {};
@@ -138,3 +202,22 @@ function normalizeOptions(options) {
138
202
  options.serveStaticTargetName ??= 'serve-static';
139
203
  return options;
140
204
  }
205
+ function determineIsRemixVite(configFilePath, workspaceRoot) {
206
+ if (configFilePath.includes('remix.config')) {
207
+ return RemixCompiler.IsClassic;
208
+ }
209
+ const fileContents = (0, fs_1.readFileSync)((0, path_1.join)(workspaceRoot, configFilePath), 'utf8');
210
+ if (fileContents.includes('@remix-run/dev') &&
211
+ (fileContents.includes('vitePlugin()') || fileContents.includes('remix()'))) {
212
+ return RemixCompiler.IsVte;
213
+ }
214
+ else {
215
+ return RemixCompiler.IsNotRemix;
216
+ }
217
+ }
218
+ var RemixCompiler;
219
+ (function (RemixCompiler) {
220
+ RemixCompiler[RemixCompiler["IsClassic"] = 1] = "IsClassic";
221
+ RemixCompiler[RemixCompiler["IsVte"] = 2] = "IsVte";
222
+ RemixCompiler[RemixCompiler["IsNotRemix"] = 3] = "IsNotRemix";
223
+ })(RemixCompiler || (RemixCompiler = {}));
@@ -0,0 +1 @@
1
+ export declare function loadViteDynamicImport(): Promise<typeof import("vite")>;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadViteDynamicImport = loadViteDynamicImport;
4
+ function loadViteDynamicImport() {
5
+ return Function('return import("vite")')();
6
+ }