@nx/remix 0.0.0-pr-22179-271588f

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.
Files changed (163) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +63 -0
  3. package/executors.json +14 -0
  4. package/generators.d.ts +14 -0
  5. package/generators.js +31 -0
  6. package/generators.json +90 -0
  7. package/index.d.ts +1 -0
  8. package/index.js +5 -0
  9. package/migrations.json +107 -0
  10. package/package.json +53 -0
  11. package/plugin.d.ts +1 -0
  12. package/plugin.js +6 -0
  13. package/plugins/component-testing/index.d.ts +30 -0
  14. package/plugins/component-testing/index.js +64 -0
  15. package/src/executors/build/build.impl.d.ts +5 -0
  16. package/src/executors/build/build.impl.js +109 -0
  17. package/src/executors/build/schema.d.ts +7 -0
  18. package/src/executors/build/schema.json +38 -0
  19. package/src/executors/serve/schema.d.ts +9 -0
  20. package/src/executors/serve/schema.json +41 -0
  21. package/src/executors/serve/serve.impl.d.ts +6 -0
  22. package/src/executors/serve/serve.impl.js +77 -0
  23. package/src/generators/action/action.impl.d.ts +3 -0
  24. package/src/generators/action/action.impl.js +39 -0
  25. package/src/generators/action/schema.d.ts +10 -0
  26. package/src/generators/action/schema.json +29 -0
  27. package/src/generators/application/__snapshots__/application.impl.spec.ts.snap +1487 -0
  28. package/src/generators/application/application.impl.d.ts +5 -0
  29. package/src/generators/application/application.impl.js +198 -0
  30. package/src/generators/application/files/common/README.md__tmpl__ +54 -0
  31. package/src/generators/application/files/common/app/nx-welcome.tsx__tmpl__ +886 -0
  32. package/src/generators/application/files/common/app/root.tsx__tmpl__ +32 -0
  33. package/src/generators/application/files/common/app/routes/_index.tsx__tmpl__ +9 -0
  34. package/src/generators/application/files/common/public/favicon.ico +0 -0
  35. package/src/generators/application/files/common/remix.config.js__tmpl__ +17 -0
  36. package/src/generators/application/files/common/remix.env.d.ts__tmpl__ +2 -0
  37. package/src/generators/application/files/common/tests/routes/_index.spec.tsx__tmpl__ +16 -0
  38. package/src/generators/application/files/common/tsconfig.app.json__tmpl__ +20 -0
  39. package/src/generators/application/files/common/tsconfig.json__tmpl__ +24 -0
  40. package/src/generators/application/files/integrated/.gitignore__tmpl__ +4 -0
  41. package/src/generators/application/files/integrated/package.json__tmpl__ +28 -0
  42. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  43. package/src/generators/application/lib/add-e2e.js +66 -0
  44. package/src/generators/application/lib/index.d.ts +3 -0
  45. package/src/generators/application/lib/index.js +6 -0
  46. package/src/generators/application/lib/normalize-options.d.ts +10 -0
  47. package/src/generators/application/lib/normalize-options.js +37 -0
  48. package/src/generators/application/lib/update-unit-test-config.d.ts +2 -0
  49. package/src/generators/application/lib/update-unit-test-config.js +55 -0
  50. package/src/generators/application/schema.d.ts +16 -0
  51. package/src/generators/application/schema.json +68 -0
  52. package/src/generators/cypress-component-configuration/cypress-component-configuration.impl.d.ts +5 -0
  53. package/src/generators/cypress-component-configuration/cypress-component-configuration.impl.js +34 -0
  54. package/src/generators/cypress-component-configuration/files/cypress.config.ts__tmpl__ +6 -0
  55. package/src/generators/cypress-component-configuration/schema.d.ts +6 -0
  56. package/src/generators/cypress-component-configuration/schema.json +41 -0
  57. package/src/generators/error-boundary/__snapshots__/error-boundary.impl.spec.ts.snap +61 -0
  58. package/src/generators/error-boundary/error-boundary.impl.d.ts +3 -0
  59. package/src/generators/error-boundary/error-boundary.impl.js +12 -0
  60. package/src/generators/error-boundary/lib/add-v2-error-boundary.d.ts +3 -0
  61. package/src/generators/error-boundary/lib/add-v2-error-boundary.js +38 -0
  62. package/src/generators/error-boundary/lib/index.d.ts +2 -0
  63. package/src/generators/error-boundary/lib/index.js +5 -0
  64. package/src/generators/error-boundary/lib/normalize-options.d.ts +3 -0
  65. package/src/generators/error-boundary/lib/normalize-options.js +17 -0
  66. package/src/generators/error-boundary/schema.d.ts +11 -0
  67. package/src/generators/error-boundary/schema.json +37 -0
  68. package/src/generators/init/init.d.ts +5 -0
  69. package/src/generators/init/init.js +60 -0
  70. package/src/generators/init/schema.d.ts +7 -0
  71. package/src/generators/init/schema.json +33 -0
  72. package/src/generators/library/__snapshots__/library.impl.spec.ts.snap +157 -0
  73. package/src/generators/library/lib/add-tsconfig-entry-points.d.ts +3 -0
  74. package/src/generators/library/lib/add-tsconfig-entry-points.js +19 -0
  75. package/src/generators/library/lib/add-unit-testing.d.ts +3 -0
  76. package/src/generators/library/lib/add-unit-testing.js +32 -0
  77. package/src/generators/library/lib/index.d.ts +4 -0
  78. package/src/generators/library/lib/index.js +7 -0
  79. package/src/generators/library/lib/normalize-options.d.ts +7 -0
  80. package/src/generators/library/lib/normalize-options.js +29 -0
  81. package/src/generators/library/lib/update-buildable-config.d.ts +2 -0
  82. package/src/generators/library/lib/update-buildable-config.js +21 -0
  83. package/src/generators/library/library.impl.d.ts +6 -0
  84. package/src/generators/library/library.impl.js +45 -0
  85. package/src/generators/library/schema.d.ts +16 -0
  86. package/src/generators/library/schema.json +74 -0
  87. package/src/generators/loader/loader.impl.d.ts +3 -0
  88. package/src/generators/loader/loader.impl.js +39 -0
  89. package/src/generators/loader/schema.d.ts +10 -0
  90. package/src/generators/loader/schema.json +29 -0
  91. package/src/generators/meta/lib/v2.impl.d.ts +3 -0
  92. package/src/generators/meta/lib/v2.impl.js +28 -0
  93. package/src/generators/meta/meta.impl.d.ts +3 -0
  94. package/src/generators/meta/meta.impl.js +7 -0
  95. package/src/generators/meta/schema.d.ts +10 -0
  96. package/src/generators/meta/schema.json +29 -0
  97. package/src/generators/preset/lib/normalize-options.d.ts +11 -0
  98. package/src/generators/preset/lib/normalize-options.js +20 -0
  99. package/src/generators/preset/preset.impl.d.ts +3 -0
  100. package/src/generators/preset/preset.impl.js +32 -0
  101. package/src/generators/preset/schema.d.ts +4 -0
  102. package/src/generators/preset/schema.json +14 -0
  103. package/src/generators/resource-route/__snapshots__/resource-route.impl.spec.ts.snap +21 -0
  104. package/src/generators/resource-route/resource-route.impl.d.ts +3 -0
  105. package/src/generators/resource-route/resource-route.impl.js +41 -0
  106. package/src/generators/resource-route/schema.d.ts +13 -0
  107. package/src/generators/resource-route/schema.json +51 -0
  108. package/src/generators/route/__snapshots__/route.impl.spec.ts.snap +95 -0
  109. package/src/generators/route/route.impl.d.ts +3 -0
  110. package/src/generators/route/route.impl.js +78 -0
  111. package/src/generators/route/schema.d.ts +15 -0
  112. package/src/generators/route/schema.json +62 -0
  113. package/src/generators/setup/schema.json +14 -0
  114. package/src/generators/setup/setup.impl.d.ts +2 -0
  115. package/src/generators/setup/setup.impl.js +34 -0
  116. package/src/generators/setup-tailwind/__snapshots__/setup-tailwind.impl.spec.ts.snap +170 -0
  117. package/src/generators/setup-tailwind/files/app/tailwind.css__tpl__ +3 -0
  118. package/src/generators/setup-tailwind/files/tailwind.config.ts__tpl__ +13 -0
  119. package/src/generators/setup-tailwind/lib/index.d.ts +1 -0
  120. package/src/generators/setup-tailwind/lib/index.js +4 -0
  121. package/src/generators/setup-tailwind/lib/update-remix-config.d.ts +2 -0
  122. package/src/generators/setup-tailwind/lib/update-remix-config.js +35 -0
  123. package/src/generators/setup-tailwind/schema.d.ts +5 -0
  124. package/src/generators/setup-tailwind/schema.json +36 -0
  125. package/src/generators/setup-tailwind/setup-tailwind.impl.d.ts +3 -0
  126. package/src/generators/setup-tailwind/setup-tailwind.impl.js +34 -0
  127. package/src/generators/storybook-configuration/__snapshots__/storybook-configuration.impl.spec.ts.snap +73 -0
  128. package/src/generators/storybook-configuration/files/vite.config.ts__tpl__ +15 -0
  129. package/src/generators/storybook-configuration/schema.d.ts +16 -0
  130. package/src/generators/storybook-configuration/schema.json +89 -0
  131. package/src/generators/storybook-configuration/storybook-configuration.impl.d.ts +4 -0
  132. package/src/generators/storybook-configuration/storybook-configuration.impl.js +26 -0
  133. package/src/generators/style/schema.d.ts +10 -0
  134. package/src/generators/style/schema.json +36 -0
  135. package/src/generators/style/style.impl.d.ts +3 -0
  136. package/src/generators/style/style.impl.js +61 -0
  137. package/src/generators/utils/update-dependencies.d.ts +2 -0
  138. package/src/generators/utils/update-dependencies.js +21 -0
  139. package/src/plugins/__snapshots__/plugin.spec.ts.snap +113 -0
  140. package/src/plugins/plugin.d.ts +9 -0
  141. package/src/plugins/plugin.js +136 -0
  142. package/src/utils/create-watch-paths.d.ts +8 -0
  143. package/src/utils/create-watch-paths.js +40 -0
  144. package/src/utils/get-default-export-name.d.ts +2 -0
  145. package/src/utils/get-default-export-name.js +8 -0
  146. package/src/utils/get-default-export.d.ts +2 -0
  147. package/src/utils/get-default-export.js +15 -0
  148. package/src/utils/insert-import.d.ts +4 -0
  149. package/src/utils/insert-import.js +54 -0
  150. package/src/utils/insert-statement-after-imports.d.ts +5 -0
  151. package/src/utils/insert-statement-after-imports.js +28 -0
  152. package/src/utils/insert-statement-in-default-function.d.ts +2 -0
  153. package/src/utils/insert-statement-in-default-function.js +23 -0
  154. package/src/utils/remix-config.d.ts +5 -0
  155. package/src/utils/remix-config.js +45 -0
  156. package/src/utils/remix-route-utils.d.ts +13 -0
  157. package/src/utils/remix-route-utils.js +70 -0
  158. package/src/utils/testing-config-utils.d.ts +4 -0
  159. package/src/utils/testing-config-utils.js +79 -0
  160. package/src/utils/upsert-links-function.d.ts +2 -0
  161. package/src/utils/upsert-links-function.js +31 -0
  162. package/src/utils/versions.d.ts +16 -0
  163. package/src/utils/versions.js +28 -0
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addV2ErrorBoundary = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const insert_import_1 = require("../../../utils/insert-import");
6
+ const insert_statement_after_imports_1 = require("../../../utils/insert-statement-after-imports");
7
+ function addV2ErrorBoundary(tree, options) {
8
+ (0, insert_import_1.insertImport)(tree, options.path, `useRouteError`, '@remix-run/react');
9
+ (0, insert_import_1.insertImport)(tree, options.path, `isRouteErrorResponse`, '@remix-run/react');
10
+ (0, insert_statement_after_imports_1.insertStatementAfterImports)(tree, options.path, (0, devkit_1.stripIndents) `
11
+ export function ErrorBoundary() {
12
+ const error = useRouteError();
13
+
14
+ // when true, this is what used to go to 'CatchBoundary'
15
+ if (isRouteErrorResponse(error)) {
16
+ return (
17
+ <div>
18
+ <h1>Oops</h1>
19
+ <p>Status: {error.status}</p>
20
+ <p>{error.data.message}</p>
21
+ </div>
22
+ );
23
+ } else if (error instanceof Error) {
24
+ return (
25
+ <div>
26
+ <h1>Error</h1>
27
+ <p>{error.message}</p>
28
+ <p>The stack trace is:</p>
29
+ <pre>{error.stack}</pre>
30
+ </div>
31
+ );
32
+ } else {
33
+ return <h1>Unknown Error</h1>;
34
+ }
35
+ }
36
+ `);
37
+ }
38
+ exports.addV2ErrorBoundary = addV2ErrorBoundary;
@@ -0,0 +1,2 @@
1
+ export * from './add-v2-error-boundary';
2
+ export * from './normalize-options';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./add-v2-error-boundary"), exports);
5
+ tslib_1.__exportStar(require("./normalize-options"), exports);
@@ -0,0 +1,3 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ import type { ErrorBoundarySchema } from '../schema';
3
+ export declare function normalizeOptions(tree: Tree, schema: ErrorBoundarySchema): Promise<ErrorBoundarySchema>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = void 0;
4
+ const remix_route_utils_1 = require("../../../utils/remix-route-utils");
5
+ async function normalizeOptions(tree, schema) {
6
+ const pathToRouteFile = schema.nameAndDirectoryFormat === 'as-provided'
7
+ ? schema.path
8
+ : await (0, remix_route_utils_1.resolveRemixRouteFile)(tree, schema.path, schema.project);
9
+ if (!tree.exists(pathToRouteFile)) {
10
+ throw new Error(`Route file specified does not exist "${pathToRouteFile}". Please ensure you pass a correct path to the file.`);
11
+ }
12
+ return {
13
+ ...schema,
14
+ path: pathToRouteFile,
15
+ };
16
+ }
17
+ exports.normalizeOptions = normalizeOptions;
@@ -0,0 +1,11 @@
1
+ import { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
2
+
3
+ export interface ErrorBoundarySchema {
4
+ path: string;
5
+ skipFormat?: false;
6
+ nameAndDirectoryFormat?: NameAndDirectoryFormat;
7
+ /**
8
+ * @deprecated Provide the `path` option instead. The project will be determined from the path provided. It will be removed in Nx v19.
9
+ */
10
+ project?: string;
11
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxRemixErrorBoundary",
4
+ "title": "Create an ErrorBoundary for a Route",
5
+ "description": "Generate an ErrorBoundary for a given route.",
6
+ "type": "object",
7
+ "examples": [
8
+ {
9
+ "command": "g error-boundary --routePath=apps/demo/app/routes/my-route.tsx",
10
+ "description": "Generate an ErrorBoundary for my-route.tsx"
11
+ }
12
+ ],
13
+ "properties": {
14
+ "path": {
15
+ "type": "string",
16
+ "description": "The path to route file relative to the project root."
17
+ },
18
+ "nameAndDirectoryFormat": {
19
+ "description": "Whether to generate the error boundary in the path as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
20
+ "type": "string",
21
+ "enum": ["as-provided", "derived"]
22
+ },
23
+ "project": {
24
+ "type": "string",
25
+ "description": "The name of the project.",
26
+ "pattern": "^[a-zA-Z].*$",
27
+ "x-deprecated": "Provide the `path` option instead and use the `as-provided` format. The project will be determined from the path provided. It will be removed in Nx v19."
28
+ },
29
+ "skipFormat": {
30
+ "type": "boolean",
31
+ "description": "Skip formatting files after generation.",
32
+ "default": false,
33
+ "x-priority": "internal"
34
+ }
35
+ },
36
+ "required": ["path"]
37
+ }
@@ -0,0 +1,5 @@
1
+ import { type Tree, GeneratorCallback } from '@nx/devkit';
2
+ import { type Schema } from './schema';
3
+ export declare function remixInitGenerator(tree: Tree, options: Schema): Promise<GeneratorCallback>;
4
+ export declare function remixInitGeneratorInternal(tree: Tree, options: Schema): Promise<GeneratorCallback>;
5
+ export default remixInitGenerator;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remixInitGeneratorInternal = exports.remixInitGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
+ const plugin_1 = require("../../plugins/plugin");
7
+ const versions_1 = require("../../utils/versions");
8
+ function addPlugin(tree) {
9
+ const nxJson = (0, devkit_1.readNxJson)(tree);
10
+ nxJson.plugins ??= [];
11
+ for (const plugin of nxJson.plugins) {
12
+ if (typeof plugin === 'string'
13
+ ? plugin === '@nx/remix/plugin'
14
+ : plugin.plugin === '@nx/remix/plugin') {
15
+ return;
16
+ }
17
+ }
18
+ nxJson.plugins.push({
19
+ plugin: '@nx/remix/plugin',
20
+ options: {
21
+ buildTargetName: 'build',
22
+ serveTargetName: 'serve',
23
+ startTargetName: 'start',
24
+ typecheckTargetName: 'typecheck',
25
+ },
26
+ });
27
+ (0, devkit_1.updateNxJson)(tree, nxJson);
28
+ }
29
+ function remixInitGenerator(tree, options) {
30
+ return remixInitGeneratorInternal(tree, { addPlugin: false, ...options });
31
+ }
32
+ exports.remixInitGenerator = remixInitGenerator;
33
+ async function remixInitGeneratorInternal(tree, options) {
34
+ const tasks = [];
35
+ if (!options.skipPackageJson) {
36
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
37
+ '@remix-run/serve': versions_1.remixVersion,
38
+ }, {
39
+ '@nx/web': versions_1.nxVersion,
40
+ '@remix-run/dev': versions_1.remixVersion,
41
+ }, undefined, options.keepExistingVersions);
42
+ tasks.push(installTask);
43
+ }
44
+ const nxJson = (0, devkit_1.readNxJson)(tree);
45
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
46
+ nxJson.useInferencePlugins !== false;
47
+ options.addPlugin ??= addPluginDefault;
48
+ if (options.addPlugin) {
49
+ addPlugin(tree);
50
+ }
51
+ if (options.updatePackageScripts) {
52
+ await (0, update_package_scripts_1.updatePackageScripts)(tree, plugin_1.createNodes);
53
+ }
54
+ if (!options.skipFormat) {
55
+ await (0, devkit_1.formatFiles)(tree);
56
+ }
57
+ return (0, devkit_1.runTasksInSerial)(...tasks);
58
+ }
59
+ exports.remixInitGeneratorInternal = remixInitGeneratorInternal;
60
+ exports.default = remixInitGenerator;
@@ -0,0 +1,7 @@
1
+ export interface Schema {
2
+ skipFormat?: boolean;
3
+ skipPackageJson?: boolean;
4
+ keepExistingVersions?: boolean;
5
+ updatePackageScripts?: boolean;
6
+ addPlugin?: boolean;
7
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxRemixInit",
4
+ "title": "Init Remix Plugin",
5
+ "description": "Initialize the Remix Plugin.",
6
+ "cli": "nx",
7
+ "type": "object",
8
+ "properties": {
9
+ "skipFormat": {
10
+ "description": "Skip formatting files.",
11
+ "type": "boolean",
12
+ "default": false
13
+ },
14
+ "skipPackageJson": {
15
+ "description": "Do not add dependencies to `package.json`.",
16
+ "type": "boolean",
17
+ "default": false
18
+ },
19
+ "keepExistingVersions": {
20
+ "type": "boolean",
21
+ "x-priority": "internal",
22
+ "description": "Keep existing dependencies versions",
23
+ "default": false
24
+ },
25
+ "updatePackageScripts": {
26
+ "type": "boolean",
27
+ "x-priority": "internal",
28
+ "description": "Update `package.json` scripts with inferred targets",
29
+ "default": false
30
+ }
31
+ },
32
+ "required": []
33
+ }
@@ -0,0 +1,157 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Remix Library Generator -projectNameAndRootFormat=as-provided --unitTestRunner should create the correct config files for testing with jest 1`] = `
4
+ "/* eslint-disable */
5
+ export default {
6
+ setupFilesAfterEnv: ['./src/test-setup.ts'],
7
+ displayName: 'test',
8
+ preset: '../jest.preset.js',
9
+ transform: {
10
+ '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
11
+ '^.+\\\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
12
+ },
13
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
14
+ coverageDirectory: '../coverage/test',
15
+ };
16
+ "
17
+ `;
18
+
19
+ exports[`Remix Library Generator -projectNameAndRootFormat=as-provided --unitTestRunner should create the correct config files for testing with jest 2`] = `
20
+ "import { installGlobals } from '@remix-run/node';
21
+ import '@testing-library/jest-dom/matchers';
22
+ installGlobals();
23
+ "
24
+ `;
25
+
26
+ exports[`Remix Library Generator -projectNameAndRootFormat=as-provided --unitTestRunner should create the correct config files for testing with vitest 1`] = `
27
+ "import { defineConfig } from 'vite';
28
+ import react from '@vitejs/plugin-react';
29
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
30
+
31
+ export default defineConfig({
32
+ root: __dirname,
33
+ cacheDir: '../node_modules/.vite/test',
34
+
35
+ plugins: [react(), nxViteTsPaths()],
36
+
37
+ // Uncomment this if you are using workers.
38
+ // worker: {
39
+ // plugins: [ nxViteTsPaths() ],
40
+ // },
41
+
42
+ test: {
43
+ setupFiles: ['./src/test-setup.ts'],
44
+ globals: true,
45
+ cache: { dir: '../node_modules/.vitest' },
46
+ environment: 'jsdom',
47
+ include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
48
+ reporters: ['default'],
49
+ coverage: { reportsDirectory: '../coverage/test', provider: 'v8' },
50
+ },
51
+ });
52
+ "
53
+ `;
54
+
55
+ exports[`Remix Library Generator -projectNameAndRootFormat=as-provided --unitTestRunner should create the correct config files for testing with vitest 2`] = `
56
+ "import { installGlobals } from '@remix-run/node';
57
+ import '@testing-library/jest-dom/matchers';
58
+ installGlobals();
59
+ "
60
+ `;
61
+
62
+ exports[`Remix Library Generator -projectNameAndRootFormat=as-provided should generate a library correctly 1`] = `
63
+ [
64
+ "test.module.css",
65
+ "test.spec.tsx",
66
+ "test.tsx",
67
+ ]
68
+ `;
69
+
70
+ exports[`Remix Library Generator -projectNameAndRootFormat=as-provided should generate a library correctly 2`] = `
71
+ {
72
+ "@proj/test": [
73
+ "test/src/index.ts",
74
+ ],
75
+ "@proj/test/server": [
76
+ "test/src/server.ts",
77
+ ],
78
+ }
79
+ `;
80
+
81
+ exports[`Remix Library Generator -projectNameAndRootFormat=derived --unitTestRunner should create the correct config files for testing with jest 1`] = `
82
+ "/* eslint-disable */
83
+ export default {
84
+ setupFilesAfterEnv: ['./src/test-setup.ts'],
85
+ displayName: 'test',
86
+ preset: '../../jest.preset.js',
87
+ transform: {
88
+ '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
89
+ '^.+\\\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
90
+ },
91
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
92
+ coverageDirectory: '../../coverage/libs/test',
93
+ };
94
+ "
95
+ `;
96
+
97
+ exports[`Remix Library Generator -projectNameAndRootFormat=derived --unitTestRunner should create the correct config files for testing with jest 2`] = `
98
+ "import { installGlobals } from '@remix-run/node';
99
+ import '@testing-library/jest-dom/matchers';
100
+ installGlobals();
101
+ "
102
+ `;
103
+
104
+ exports[`Remix Library Generator -projectNameAndRootFormat=derived --unitTestRunner should create the correct config files for testing with vitest 1`] = `
105
+ "import { defineConfig } from 'vite';
106
+ import react from '@vitejs/plugin-react';
107
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
108
+
109
+ export default defineConfig({
110
+ root: __dirname,
111
+ cacheDir: '../../node_modules/.vite/libs/test',
112
+
113
+ plugins: [react(), nxViteTsPaths()],
114
+
115
+ // Uncomment this if you are using workers.
116
+ // worker: {
117
+ // plugins: [ nxViteTsPaths() ],
118
+ // },
119
+
120
+ test: {
121
+ setupFiles: ['./src/test-setup.ts'],
122
+ globals: true,
123
+ cache: { dir: '../../node_modules/.vitest' },
124
+ environment: 'jsdom',
125
+ include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
126
+ reporters: ['default'],
127
+ coverage: { reportsDirectory: '../../coverage/libs/test', provider: 'v8' },
128
+ },
129
+ });
130
+ "
131
+ `;
132
+
133
+ exports[`Remix Library Generator -projectNameAndRootFormat=derived --unitTestRunner should create the correct config files for testing with vitest 2`] = `
134
+ "import { installGlobals } from '@remix-run/node';
135
+ import '@testing-library/jest-dom/matchers';
136
+ installGlobals();
137
+ "
138
+ `;
139
+
140
+ exports[`Remix Library Generator -projectNameAndRootFormat=derived should generate a library correctly 1`] = `
141
+ [
142
+ "test.module.css",
143
+ "test.spec.tsx",
144
+ "test.tsx",
145
+ ]
146
+ `;
147
+
148
+ exports[`Remix Library Generator -projectNameAndRootFormat=derived should generate a library correctly 2`] = `
149
+ {
150
+ "@proj/libs/test": [
151
+ "libs/test/src/index.ts",
152
+ ],
153
+ "@proj/libs/test/server": [
154
+ "libs/test/src/server.ts",
155
+ ],
156
+ }
157
+ `;
@@ -0,0 +1,3 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { RemixLibraryOptions } from './normalize-options';
3
+ export declare function addTsconfigEntryPoints(tree: Tree, options: RemixLibraryOptions): void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addTsconfigEntryPoints = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const js_1 = require("@nx/js");
6
+ function addTsconfigEntryPoints(tree, options) {
7
+ const { sourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
8
+ const serverFilePath = (0, devkit_1.joinPathFragments)(sourceRoot, 'server.ts');
9
+ tree.write(serverFilePath, `// This file should be used to export ONLY server-code from the library.`);
10
+ const baseTsConfig = (0, js_1.getRootTsConfigPathInTree)(tree);
11
+ (0, devkit_1.updateJson)(tree, baseTsConfig, (json) => {
12
+ if (json.compilerOptions.paths &&
13
+ json.compilerOptions.paths[options.importPath]) {
14
+ json.compilerOptions.paths[(0, devkit_1.joinPathFragments)(options.importPath, 'server')] = [serverFilePath];
15
+ }
16
+ return json;
17
+ });
18
+ }
19
+ exports.addTsconfigEntryPoints = addTsconfigEntryPoints;
@@ -0,0 +1,3 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ import type { RemixLibraryOptions } from './normalize-options';
3
+ export declare function addUnitTestingSetup(tree: Tree, options: RemixLibraryOptions): import("@nx/devkit").GeneratorCallback;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addUnitTestingSetup = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const testing_config_utils_1 = require("../../../utils/testing-config-utils");
6
+ const versions_1 = require("../../../utils/versions");
7
+ function addUnitTestingSetup(tree, options) {
8
+ const pathToTestSetup = (0, devkit_1.joinPathFragments)(options.projectRoot, 'src/test-setup.ts');
9
+ let testSetupFileContents = '';
10
+ if (tree.exists(pathToTestSetup)) {
11
+ testSetupFileContents = tree.read(pathToTestSetup, 'utf-8');
12
+ }
13
+ tree.write(pathToTestSetup, (0, devkit_1.stripIndents) `${testSetupFileContents}
14
+ import { installGlobals } from '@remix-run/node';
15
+ import "@testing-library/jest-dom/matchers";
16
+ installGlobals();`);
17
+ if (options.unitTestRunner === 'vitest') {
18
+ const pathToVitestConfig = (0, devkit_1.joinPathFragments)(options.projectRoot, `vite.config.ts`);
19
+ (0, testing_config_utils_1.updateVitestTestSetup)(tree, pathToVitestConfig, './src/test-setup.ts');
20
+ }
21
+ else if (options.unitTestRunner === 'jest') {
22
+ const pathToJestConfig = (0, devkit_1.joinPathFragments)(options.projectRoot, `jest.config.ts`);
23
+ (0, testing_config_utils_1.updateJestTestSetup)(tree, pathToJestConfig, './src/test-setup.ts');
24
+ }
25
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
26
+ '@testing-library/jest-dom': versions_1.testingLibraryJestDomVersion,
27
+ '@testing-library/react': versions_1.testingLibraryReactVersion,
28
+ '@testing-library/user-event': versions_1.testingLibraryUserEventsVersion,
29
+ '@remix-run/node': (0, versions_1.getRemixVersion)(tree),
30
+ });
31
+ }
32
+ exports.addUnitTestingSetup = addUnitTestingSetup;
@@ -0,0 +1,4 @@
1
+ export * from './add-tsconfig-entry-points';
2
+ export * from './add-unit-testing';
3
+ export * from './normalize-options';
4
+ export * from './update-buildable-config';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./add-tsconfig-entry-points"), exports);
5
+ tslib_1.__exportStar(require("./add-unit-testing"), exports);
6
+ tslib_1.__exportStar(require("./normalize-options"), exports);
7
+ tslib_1.__exportStar(require("./update-buildable-config"), exports);
@@ -0,0 +1,7 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ import type { NxRemixGeneratorSchema } from '../schema';
3
+ export interface RemixLibraryOptions extends NxRemixGeneratorSchema {
4
+ projectName: string;
5
+ projectRoot: string;
6
+ }
7
+ export declare function normalizeOptions(tree: Tree, options: NxRemixGeneratorSchema): Promise<RemixLibraryOptions>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
7
+ async function normalizeOptions(tree, options) {
8
+ const { projectName, projectRoot, projectNameAndRootFormat } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
9
+ name: options.name,
10
+ projectType: 'library',
11
+ directory: options.directory,
12
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
13
+ callingGenerator: '@nx/remix:library',
14
+ });
15
+ const nxJson = (0, devkit_1.readNxJson)(tree);
16
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
17
+ nxJson.useInferencePlugins !== false;
18
+ options.addPlugin ??= addPluginDefault;
19
+ const importPath = options.importPath ?? (0, get_import_path_1.getImportPath)(tree, projectRoot);
20
+ return {
21
+ ...options,
22
+ unitTestRunner: options.unitTestRunner ?? 'vitest',
23
+ importPath,
24
+ projectName,
25
+ projectRoot,
26
+ projectNameAndRootFormat,
27
+ };
28
+ }
29
+ exports.normalizeOptions = normalizeOptions;
@@ -0,0 +1,2 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ export declare function updateBuildableConfig(tree: Tree, name: string): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateBuildableConfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function updateBuildableConfig(tree, name) {
6
+ // Nest dist under project root to we can link it
7
+ const project = (0, devkit_1.readProjectConfiguration)(tree, name);
8
+ project.targets.build.options = {
9
+ ...project.targets.build.options,
10
+ format: ['cjs'],
11
+ outputPath: (0, devkit_1.joinPathFragments)(project.root, 'dist'),
12
+ };
13
+ (0, devkit_1.updateProjectConfiguration)(tree, name, project);
14
+ // Point to nested dist for yarn/npm/pnpm workspaces
15
+ (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(project.root, 'package.json'), (json) => {
16
+ json.main = './dist/index.cjs.js';
17
+ json.typings = './dist/index.d.ts';
18
+ return json;
19
+ });
20
+ }
21
+ exports.updateBuildableConfig = updateBuildableConfig;
@@ -0,0 +1,6 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import { GeneratorCallback } from '@nx/devkit';
3
+ import type { NxRemixGeneratorSchema } from './schema';
4
+ export declare function remixLibraryGenerator(tree: Tree, schema: NxRemixGeneratorSchema): Promise<GeneratorCallback>;
5
+ export declare function remixLibraryGeneratorInternal(tree: Tree, schema: NxRemixGeneratorSchema): Promise<GeneratorCallback>;
6
+ export default remixLibraryGenerator;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remixLibraryGeneratorInternal = exports.remixLibraryGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const eslint_1 = require("@nx/eslint");
6
+ const react_1 = require("@nx/react");
7
+ const lib_1 = require("./lib");
8
+ async function remixLibraryGenerator(tree, schema) {
9
+ return remixLibraryGeneratorInternal(tree, { addPlugin: false, ...schema });
10
+ }
11
+ exports.remixLibraryGenerator = remixLibraryGenerator;
12
+ async function remixLibraryGeneratorInternal(tree, schema) {
13
+ const tasks = [];
14
+ const options = await (0, lib_1.normalizeOptions)(tree, schema);
15
+ const libGenTask = await (0, react_1.libraryGenerator)(tree, {
16
+ name: options.projectName,
17
+ style: options.style,
18
+ unitTestRunner: options.unitTestRunner,
19
+ tags: options.tags,
20
+ importPath: options.importPath,
21
+ directory: options.projectRoot,
22
+ projectNameAndRootFormat: 'as-provided',
23
+ skipFormat: true,
24
+ skipTsConfig: false,
25
+ linter: eslint_1.Linter.EsLint,
26
+ component: true,
27
+ buildable: options.buildable,
28
+ addPlugin: options.addPlugin,
29
+ });
30
+ tasks.push(libGenTask);
31
+ if (options.unitTestRunner && options.unitTestRunner !== 'none') {
32
+ const pkgInstallTask = (0, lib_1.addUnitTestingSetup)(tree, options);
33
+ tasks.push(pkgInstallTask);
34
+ }
35
+ (0, lib_1.addTsconfigEntryPoints)(tree, options);
36
+ if (options.buildable) {
37
+ (0, lib_1.updateBuildableConfig)(tree, options.projectName);
38
+ }
39
+ if (!options.skipFormat) {
40
+ await (0, devkit_1.formatFiles)(tree);
41
+ }
42
+ return (0, devkit_1.runTasksInSerial)(...tasks);
43
+ }
44
+ exports.remixLibraryGeneratorInternal = remixLibraryGeneratorInternal;
45
+ exports.default = remixLibraryGenerator;
@@ -0,0 +1,16 @@
1
+ import { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import { SupportedStyles } from '@nx/react';
3
+
4
+ export interface NxRemixGeneratorSchema {
5
+ name: string;
6
+ style: SupportedStyles;
7
+ directory?: string;
8
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
9
+ tags?: string;
10
+ importPath?: string;
11
+ buildable?: boolean;
12
+ unitTestRunner?: 'jest' | 'vitest' | 'none';
13
+ js?: boolean;
14
+ skipFormat?: boolean;
15
+ addPlugin?: boolean;
16
+ }