@celljs/vite 0.0.0-stage → 4.1.0

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 (166) hide show
  1. package/README.md +29 -2
  2. package/assets/favicon.ico +0 -0
  3. package/lib/builder/cell-builder.d.ts +19 -0
  4. package/lib/builder/cell-builder.d.ts.map +1 -0
  5. package/lib/builder/cell-builder.js +59 -0
  6. package/lib/builder/cell-builder.js.map +1 -0
  7. package/lib/builder/cell-builder.spec.d.ts +2 -0
  8. package/lib/builder/cell-builder.spec.d.ts.map +1 -0
  9. package/lib/builder/cell-builder.spec.js +280 -0
  10. package/lib/builder/cell-builder.spec.js.map +1 -0
  11. package/lib/constants.d.ts +24 -0
  12. package/lib/constants.d.ts.map +1 -0
  13. package/lib/constants.js +23 -0
  14. package/lib/constants.js.map +1 -0
  15. package/lib/dev/cell-dev-server.d.ts +113 -0
  16. package/lib/dev/cell-dev-server.d.ts.map +1 -0
  17. package/lib/dev/cell-dev-server.js +307 -0
  18. package/lib/dev/cell-dev-server.js.map +1 -0
  19. package/lib/dev/cell-dev-server.spec.d.ts +2 -0
  20. package/lib/dev/cell-dev-server.spec.d.ts.map +1 -0
  21. package/lib/dev/cell-dev-server.spec.js +188 -0
  22. package/lib/dev/cell-dev-server.spec.js.map +1 -0
  23. package/lib/expression/expression-evaluator.d.ts +28 -0
  24. package/lib/expression/expression-evaluator.d.ts.map +1 -0
  25. package/lib/expression/expression-evaluator.js +91 -0
  26. package/lib/expression/expression-evaluator.js.map +1 -0
  27. package/lib/expression/expression-evaluator.spec.d.ts +2 -0
  28. package/lib/expression/expression-evaluator.spec.d.ts.map +1 -0
  29. package/lib/expression/expression-evaluator.spec.js +48 -0
  30. package/lib/expression/expression-evaluator.spec.js.map +1 -0
  31. package/lib/generator/config-generator.d.ts +18 -0
  32. package/lib/generator/config-generator.d.ts.map +1 -0
  33. package/lib/generator/config-generator.js +45 -0
  34. package/lib/generator/config-generator.js.map +1 -0
  35. package/lib/generator/container-generator.d.ts +13 -0
  36. package/lib/generator/container-generator.d.ts.map +1 -0
  37. package/lib/generator/container-generator.js +41 -0
  38. package/lib/generator/container-generator.js.map +1 -0
  39. package/lib/generator/generator.spec.d.ts +2 -0
  40. package/lib/generator/generator.spec.d.ts.map +1 -0
  41. package/lib/generator/generator.spec.js +61 -0
  42. package/lib/generator/generator.spec.js.map +1 -0
  43. package/lib/generator/html-generator.d.ts +13 -0
  44. package/lib/generator/html-generator.d.ts.map +1 -0
  45. package/lib/generator/html-generator.js +42 -0
  46. package/lib/generator/html-generator.js.map +1 -0
  47. package/lib/index.d.ts +21 -0
  48. package/lib/index.d.ts.map +1 -0
  49. package/lib/index.js +21 -0
  50. package/lib/index.js.map +1 -0
  51. package/lib/output/asset-embedder.d.ts +19 -0
  52. package/lib/output/asset-embedder.d.ts.map +1 -0
  53. package/lib/output/asset-embedder.js +35 -0
  54. package/lib/output/asset-embedder.js.map +1 -0
  55. package/lib/output/externals-copier.d.ts +20 -0
  56. package/lib/output/externals-copier.d.ts.map +1 -0
  57. package/lib/output/externals-copier.js +62 -0
  58. package/lib/output/externals-copier.js.map +1 -0
  59. package/lib/output/externals-copier.spec.d.ts +2 -0
  60. package/lib/output/externals-copier.spec.d.ts.map +1 -0
  61. package/lib/output/externals-copier.spec.js +30 -0
  62. package/lib/output/externals-copier.spec.js.map +1 -0
  63. package/lib/output/output-writer.d.ts +39 -0
  64. package/lib/output/output-writer.d.ts.map +1 -0
  65. package/lib/output/output-writer.js +102 -0
  66. package/lib/output/output-writer.js.map +1 -0
  67. package/lib/output/output-writer.spec.d.ts +2 -0
  68. package/lib/output/output-writer.spec.d.ts.map +1 -0
  69. package/lib/output/output-writer.spec.js +34 -0
  70. package/lib/output/output-writer.spec.js.map +1 -0
  71. package/lib/plugin/cell-plugin.d.ts +134 -0
  72. package/lib/plugin/cell-plugin.d.ts.map +1 -0
  73. package/lib/plugin/cell-plugin.js +429 -0
  74. package/lib/plugin/cell-plugin.js.map +1 -0
  75. package/lib/plugin/cell-plugin.spec.d.ts +2 -0
  76. package/lib/plugin/cell-plugin.spec.d.ts.map +1 -0
  77. package/lib/plugin/cell-plugin.spec.js +74 -0
  78. package/lib/plugin/cell-plugin.spec.js.map +1 -0
  79. package/lib/plugin/node-polyfills.d.ts +13 -0
  80. package/lib/plugin/node-polyfills.d.ts.map +1 -0
  81. package/lib/plugin/node-polyfills.js +55 -0
  82. package/lib/plugin/node-polyfills.js.map +1 -0
  83. package/lib/plugin/node-polyfills.spec.d.ts +2 -0
  84. package/lib/plugin/node-polyfills.spec.d.ts.map +1 -0
  85. package/lib/plugin/node-polyfills.spec.js +16 -0
  86. package/lib/plugin/node-polyfills.spec.js.map +1 -0
  87. package/lib/project/component-collector.d.ts +32 -0
  88. package/lib/project/component-collector.d.ts.map +1 -0
  89. package/lib/project/component-collector.js +93 -0
  90. package/lib/project/component-collector.js.map +1 -0
  91. package/lib/project/config-loader.d.ts +16 -0
  92. package/lib/project/config-loader.d.ts.map +1 -0
  93. package/lib/project/config-loader.js +76 -0
  94. package/lib/project/config-loader.js.map +1 -0
  95. package/lib/project/env-overrides.d.ts +23 -0
  96. package/lib/project/env-overrides.d.ts.map +1 -0
  97. package/lib/project/env-overrides.js +48 -0
  98. package/lib/project/env-overrides.js.map +1 -0
  99. package/lib/project/env-overrides.spec.d.ts +2 -0
  100. package/lib/project/env-overrides.spec.d.ts.map +1 -0
  101. package/lib/project/env-overrides.spec.js +41 -0
  102. package/lib/project/env-overrides.spec.js.map +1 -0
  103. package/lib/project/module-resolver.d.ts +15 -0
  104. package/lib/project/module-resolver.d.ts.map +1 -0
  105. package/lib/project/module-resolver.js +32 -0
  106. package/lib/project/module-resolver.js.map +1 -0
  107. package/lib/project/project-loader.d.ts +54 -0
  108. package/lib/project/project-loader.d.ts.map +1 -0
  109. package/lib/project/project-loader.js +117 -0
  110. package/lib/project/project-loader.js.map +1 -0
  111. package/lib/project/project-loader.spec.d.ts +2 -0
  112. package/lib/project/project-loader.spec.d.ts.map +1 -0
  113. package/lib/project/project-loader.spec.js +178 -0
  114. package/lib/project/project-loader.spec.js.map +1 -0
  115. package/lib/test/fixture-project.d.ts +17 -0
  116. package/lib/test/fixture-project.d.ts.map +1 -0
  117. package/lib/test/fixture-project.js +43 -0
  118. package/lib/test/fixture-project.js.map +1 -0
  119. package/lib/testing/memory-http.d.ts +82 -0
  120. package/lib/testing/memory-http.d.ts.map +1 -0
  121. package/lib/testing/memory-http.js +210 -0
  122. package/lib/testing/memory-http.js.map +1 -0
  123. package/lib/testing/test-app.d.ts +54 -0
  124. package/lib/testing/test-app.d.ts.map +1 -0
  125. package/lib/testing/test-app.js +132 -0
  126. package/lib/testing/test-app.js.map +1 -0
  127. package/lib/testing/test-app.spec.d.ts +2 -0
  128. package/lib/testing/test-app.spec.d.ts.map +1 -0
  129. package/lib/testing/test-app.spec.js +115 -0
  130. package/lib/testing/test-app.spec.js.map +1 -0
  131. package/lib/utils/config-util.d.ts +6 -0
  132. package/lib/utils/config-util.d.ts.map +1 -0
  133. package/lib/utils/config-util.js +25 -0
  134. package/lib/utils/config-util.js.map +1 -0
  135. package/lib/utils/config-util.spec.d.ts +2 -0
  136. package/lib/utils/config-util.spec.d.ts.map +1 -0
  137. package/lib/utils/config-util.spec.js +22 -0
  138. package/lib/utils/config-util.spec.js.map +1 -0
  139. package/lib/utils/tsconfig-util.d.ts +5 -0
  140. package/lib/utils/tsconfig-util.d.ts.map +1 -0
  141. package/lib/utils/tsconfig-util.js +21 -0
  142. package/lib/utils/tsconfig-util.js.map +1 -0
  143. package/package.json +50 -4
  144. package/src/builder/cell-builder.ts +72 -0
  145. package/src/constants.ts +30 -0
  146. package/src/dev/cell-dev-server.ts +387 -0
  147. package/src/expression/expression-evaluator.ts +99 -0
  148. package/src/generator/config-generator.ts +45 -0
  149. package/src/generator/container-generator.ts +41 -0
  150. package/src/generator/html-generator.ts +43 -0
  151. package/src/index.ts +20 -0
  152. package/src/output/asset-embedder.ts +42 -0
  153. package/src/output/externals-copier.ts +64 -0
  154. package/src/output/output-writer.ts +113 -0
  155. package/src/plugin/cell-plugin.ts +481 -0
  156. package/src/plugin/node-polyfills.ts +57 -0
  157. package/src/project/component-collector.ts +107 -0
  158. package/src/project/config-loader.ts +77 -0
  159. package/src/project/env-overrides.ts +55 -0
  160. package/src/project/module-resolver.ts +39 -0
  161. package/src/project/project-loader.ts +153 -0
  162. package/src/test/fixture-project.ts +50 -0
  163. package/src/testing/memory-http.ts +238 -0
  164. package/src/testing/test-app.ts +155 -0
  165. package/src/utils/config-util.ts +21 -0
  166. package/src/utils/tsconfig-util.ts +19 -0
@@ -0,0 +1,62 @@
1
+ import { cpSync, existsSync, mkdirSync, readFileSync, realpathSync } from 'node:fs';
2
+ import { dirname, join, sep } from 'node:path';
3
+ /**
4
+ * Copies installed external packages, with their production dependencies, into
5
+ * `<outDir>/node_modules` so the server bundle runs from its own directory. Packages that are not
6
+ * installed are skipped: optional dependencies may legitimately be absent at runtime.
7
+ */
8
+ export class ExternalsCopier {
9
+ root;
10
+ outDir;
11
+ found = new Map();
12
+ constructor(root, outDir) {
13
+ this.root = root;
14
+ this.outDir = outDir;
15
+ }
16
+ /** Returns the names of the copied packages. */
17
+ copy(names) {
18
+ for (const name of names) {
19
+ this.visit(name, this.root);
20
+ }
21
+ for (const [name, dir] of this.found) {
22
+ const target = join(this.outDir, 'node_modules', name);
23
+ if (existsSync(target)) {
24
+ continue;
25
+ }
26
+ mkdirSync(dirname(target), { recursive: true });
27
+ cpSync(dir, target, { recursive: true, dereference: true, filter: src => !src.slice(dir.length).split(sep).includes('node_modules') });
28
+ }
29
+ return [...this.found.keys()];
30
+ }
31
+ visit(name, from) {
32
+ if (this.found.has(name)) {
33
+ return;
34
+ }
35
+ const manifest = this.findManifest(name, from);
36
+ if (!manifest) {
37
+ return;
38
+ }
39
+ const dir = realpathSync(dirname(manifest));
40
+ this.found.set(name, dir);
41
+ const pkg = JSON.parse(readFileSync(manifest, 'utf8'));
42
+ for (const dep of Object.keys({ ...pkg.dependencies, ...pkg.optionalDependencies })) {
43
+ this.visit(dep, dir);
44
+ }
45
+ }
46
+ /**
47
+ * The package.json of `name` as Node finds the package from `from`. Looked up on disk rather than
48
+ * with `require.resolve('<name>/package.json')`, which fails for packages whose `exports` leave it out.
49
+ */
50
+ findManifest(name, from) {
51
+ for (let dir = from;; dir = dirname(dir)) {
52
+ const manifest = join(dir, 'node_modules', name, 'package.json');
53
+ if (existsSync(manifest)) {
54
+ return manifest;
55
+ }
56
+ if (dirname(dir) === dir) {
57
+ return undefined;
58
+ }
59
+ }
60
+ }
61
+ }
62
+ //# sourceMappingURL=externals-copier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externals-copier.js","sourceRoot":"","sources":["../../src/output/externals-copier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE/C;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAID,IAAI;IACJ,MAAM;IAJV,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IAErD,YACuB,IAAY,EACZ,MAAc;oBADd,IAAI;sBACJ,MAAM;IAC1B,CAAC;IAEJ,gDAAgD;IAChD,IAAI,CAAC,KAAe;QAChB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACnC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC;YACvD,IAAI,UAAU,CAAC,MAAM,CAAC,E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;OAGG;IACO,YAAY,CAAC,IAAY,EAAE,IAAY;QAC7C,KAAK,IAAI,GAAG,GAAG,IAAI,GAAI,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;YACjE,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACvB,OAAO,QAAQ,CAAC;YACpB,CAAC;YACD,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC;gBACvB,OAAO,SAAS,CAAC;YACrB,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=externals-copier.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externals-copier.spec.d.ts","sourceRoot":"","sources":["../../src/output/externals-copier.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ import { afterEach, describe, expect, it } from 'bun:test';
2
+ import { existsSync } from 'node:fs';
3
+ import { FixtureProject } from '../test/fixture-project.js';
4
+ import { ExternalsCopier } from './externals-copier.js';
5
+ describe('ExternalsCopier', () => {
6
+ let fixture;
7
+ afterEach(() => fixture?.dispose());
8
+ it('copies installed externals with their dependencies and skips missing ones', () => {
9
+ fixture = new FixtureProject('externals')
10
+ .file('package.json', { name: 'app' })
11
+ .dependency('native-db', { dependencies: { bindings: '*' } }, { 'index.js': 'module.exports = 1;', 'node_modules/ignored/index.js': '' })
12
+ .dependency('bindings', {}, { 'index.js': '' });
13
+ const copied = new ExternalsCopier(fixture.root, fixture.path('out')).copy(['native-db', 'not-installed']);
14
+ expect(copied.sort()).toEqual(['bindings', 'native-db']);
15
+ expect(existsSync(fixture.path('out/node_modules/native-db/index.js'))).toBe(true);
16
+ expect(existsSync(fixture.path('out/node_modules/bindings/package.json'))).toBe(true);
17
+ expect(existsSync(fixture.path('out/node_modules/native-db/node_modules'))).toBe(false);
18
+ });
19
+ it('copies externals whose exports leave out package.json', () => {
20
+ fixture = new FixtureProject('externals-esm')
21
+ .file('package.json', { name: 'app' })
22
+ .dependency('esm-only', { type: 'module', exports: { '.': { import: './index.js' } }, dependencies: { helper: '*' } }, { 'index.js': 'export default 1;' })
23
+ .dependency('helper', { exports: { '.': './index.js' } }, { 'index.js': '' });
24
+ const copied = new ExternalsCopier(fixture.root, fixture.path('out')).copy(['esm-only']);
25
+ expect(copied.sort()).toEqual(['esm-only', 'helper']);
26
+ expect(existsSync(fixture.path('out/node_modules/esm-only/index.js'))).toBe(true);
27
+ expect(existsSync(fixture.path('out/node_modules/helper/index.js'))).toBe(true);
28
+ });
29
+ });
30
+ //# sourceMappingURL=externals-copier.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externals-copier.spec.js","sourceRoot":"","sources":["../../src/output/externals-copier.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,IAAI,OAAuB,CAAC;IAE5B,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IAEpC,EAAE,CAAC,2EAA2E,EAAE,GAAG,EAAE;QACjF,OAAO,GAAG,IAAI,cAAc,CAAC,WAAW,CAAC;aACpC,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;aACrC,UAAU,CAAC,WAAW,EAAE,EAAE,YAAY,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,UA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,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;QAClF,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;QACzF,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;QACtD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClF,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { OutputManifest, ProjectModel } from '@celljs/kit';
2
+ /** Kept for importers of `@celljs/vite`; the type lives in `@celljs/kit`. */
3
+ export type { OutputManifest };
4
+ /**
5
+ * Writes everything around the bundles: generated code under `.cell/generated` (so agents and humans
6
+ * can read what was built), frontend static files, server externals and `manifest.json`.
7
+ */
8
+ export declare class OutputWriter {
9
+ protected readonly model: ProjectModel;
10
+ protected readonly outDir: string;
11
+ protected readonly format: 'esm' | 'cjs';
12
+ protected readonly preset?: string | undefined;
13
+ static readonly ASSET_DIRS: string[];
14
+ static readonly DEFAULT_FAVICON: string;
15
+ constructor(model: ProjectModel, outDir: string, format: 'esm' | 'cjs', preset?: string | undefined);
16
+ get publicDir(): string;
17
+ get serverDir(): string;
18
+ /**
19
+ * Before a build: a previous Cell output (it has manifest.json) is removed entirely, so files a
20
+ * preset wrote last time (a start script, a platform configuration) do not linger; in another
21
+ * directory only the server bundle is replaced.
22
+ */
23
+ clean(): void;
24
+ get serverEntry(): string;
25
+ get generatedDir(): string;
26
+ writeGenerated(relative: string, content: string): void;
27
+ /**
28
+ * The file that `copyFrontendFiles` puts at `path` of the public directory (`/favicon.ico`,
29
+ * `/assets/...`), for `cell dev`, which serves them from where they are. The first component
30
+ * that has the file wins, as in the copy.
31
+ */
32
+ frontendFile(path: string): string | undefined;
33
+ copyFrontendFiles(): void;
34
+ copyExternals(names: string[]): string[];
35
+ /** `single`: the frontend is inside the server bundle. */
36
+ writeManifest(single?: boolean): OutputManifest;
37
+ protected write(file: string, content: string): void;
38
+ }
39
+ //# sourceMappingURL=output-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-writer.d.ts","sourceRoot":"","sources":["../../src/output/output-writer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhE,6EAA6E;AAC7E,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B;;;GAGG;AACH,qBAAa,YAAY;IAKjB,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,YAAY;IACtC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACjC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK;IACxC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IAPtC,MAAM,CAAC,QAAQ,CAAC,UAAU,WAAkD;IAC5E,MAAM,CAAC,QAAQ,CAAC,eAAe,SAAuE;IAEtG,YACuB,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,KAAK,GAAG,KAAK,EACrB,MAAM,CAAC,EAAE,MAAM,YAAA,EAClC;IAEJ,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;;;OAIG;IACH,KAAK,IAAI,IAAI,CAMZ;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAEtD;IAED;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAW7C;IAED,iBAAiB,IAAI,IAAI,CAUxB;IAED,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAEvC;IAED,0DAA0D;IAC1D,aAAa,CAAC,MAAM,UAAQ,GAAG,cAAc,CAc5C;IAED,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAGnD;CACJ"}
@@ -0,0 +1,102 @@
1
+ import { cpSync, existsSync, mkdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { ExternalsCopier } from './externals-copier.js';
5
+ /**
6
+ * Writes everything around the bundles: generated code under `.cell/generated` (so agents and humans
7
+ * can read what was built), frontend static files, server externals and `manifest.json`.
8
+ */
9
+ export class OutputWriter {
10
+ model;
11
+ outDir;
12
+ format;
13
+ preset;
14
+ static ASSET_DIRS = ['assets', 'src/assets', 'src/browser/assets'];
15
+ static DEFAULT_FAVICON = fileURLToPath(new URL('../../assets/favicon.ico', import.meta.url));
16
+ constructor(model, outDir, format, preset) {
17
+ this.model = model;
18
+ this.outDir = outDir;
19
+ this.format = format;
20
+ this.preset = preset;
21
+ }
22
+ get publicDir() {
23
+ return join(this.outDir, 'public');
24
+ }
25
+ get serverDir() {
26
+ return join(this.outDir, 'server');
27
+ }
28
+ /**
29
+ * Before a build: a previous Cell output (it has manifest.json) is removed entirely, so files a
30
+ * preset wrote last time (a start script, a platform configuration) do not linger; in another
31
+ * directory only the server bundle is replaced.
32
+ */
33
+ clean() {
34
+ if (existsSync(join(this.outDir, 'manifest.json'))) {
35
+ rmSync(this.outDir, { recursive: true, force: true });
36
+ }
37
+ else if (this.model.targets.includes('backend')) {
38
+ rmSync(this.serverDir, { recursive: true, force: true });
39
+ }
40
+ }
41
+ get serverEntry() {
42
+ return this.format === 'esm' ? 'index.mjs' : 'index.cjs';
43
+ }
44
+ get generatedDir() {
45
+ return join(this.model.root, '.cell', 'generated');
46
+ }
47
+ writeGenerated(relative, content) {
48
+ this.write(join(this.generatedDir, relative), content);
49
+ }
50
+ /**
51
+ * The file that `copyFrontendFiles` puts at `path` of the public directory (`/favicon.ico`,
52
+ * `/assets/...`), for `cell dev`, which serves them from where they are. The first component
53
+ * that has the file wins, as in the copy.
54
+ */
55
+ frontendFile(path) {
56
+ if (path === '/favicon.ico') {
57
+ return [join(this.model.root, 'favicon.ico'), OutputWriter.DEFAULT_FAVICON].find(existsSync);
58
+ }
59
+ const asset = /^\/assets\/(.+)$/.exec(path)?.[1];
60
+ if (!asset || asset.split('/').includes('..')) {
61
+ return undefined;
62
+ }
63
+ return this.model.components
64
+ .flatMap(component => OutputWriter.ASSET_DIRS.map(dir => join(component.dir, dir, asset)))
65
+ .find(file => existsSync(file) && statSync(file).isFile());
66
+ }
67
+ copyFrontendFiles() {
68
+ const favicon = [join(this.model.root, 'favicon.ico'), OutputWriter.DEFAULT_FAVICON].find(existsSync);
69
+ if (favicon) {
70
+ cpSync(favicon, join(this.publicDir, 'favicon.ico'));
71
+ }
72
+ for (const component of this.model.components) {
73
+ for (const dir of OutputWriter.ASSET_DIRS.map(d => join(component.dir, d)).filter(existsSync)) {
74
+ cpSync(dir, join(this.publicDir, 'assets'), { recursive: true, force: false });
75
+ }
76
+ }
77
+ }
78
+ copyExternals(names) {
79
+ return new ExternalsCopier(this.model.root, this.serverDir).copy(names);
80
+ }
81
+ /** `single`: the frontend is inside the server bundle. */
82
+ writeManifest(single = false) {
83
+ const hasServer = this.model.targets.includes('backend');
84
+ const hasPublic = this.model.targets.includes('frontend') && !single;
85
+ const manifest = {
86
+ schemaVersion: 1,
87
+ preset: this.preset,
88
+ format: this.format,
89
+ targets: this.model.targets,
90
+ server: hasServer ? `server/${this.serverEntry}` : undefined,
91
+ public: hasPublic ? 'public' : undefined,
92
+ ...(single ? { single: true } : {}),
93
+ };
94
+ this.write(join(this.outDir, 'manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`);
95
+ return manifest;
96
+ }
97
+ write(file, content) {
98
+ mkdirSync(dirname(file), { recursive: true });
99
+ writeFileSync(file, content);
100
+ }
101
+ }
102
+ //# sourceMappingURL=output-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-writer.js","sourceRoot":"","sources":["../../src/output/output-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAKxD;;;GAGG;AACH,MAAM,OAAO,YAAY;IAKE,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IAP7B,MAAM,CAAU,UAAU,GAAG,CAAC,QAAQ,EAAE,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAC5E,MAAM,CAAU,eAAe,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,0BAA0B,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAEtG,YACuB,KAAmB,EACnB,MAAc,EACd,MAAqB,EACrB,MAAe;qBAHf,KAAK;sBACL,MAAM;sBACN,MAAM;sBACN,MAAM;IAC1B,CAAC;IAEJ,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,SAAS;QACT,OAAO,IAAI,CA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C,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;CACJ"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=output-writer.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-writer.spec.d.ts","sourceRoot":"","sources":["../../src/output/output-writer.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { afterAll, describe, expect, it } from 'bun:test';
2
+ import { FixtureProject } from '../test/fixture-project.js';
3
+ import { OutputWriter } from './output-writer.js';
4
+ describe('OutputWriter.frontendFile', () => {
5
+ const fixture = new FixtureProject('output-frontend-file')
6
+ .file('favicon.ico', 'project icon')
7
+ .file('src/browser/assets/logo.png', 'project logo')
8
+ .file('src/browser/assets/shared.txt', 'project')
9
+ .dependency('@x/ui', {}, { 'assets/shared.txt': 'ui', 'assets/ui.css': 'ui css' });
10
+ const model = {
11
+ root: fixture.root,
12
+ targets: ['frontend'],
13
+ components: [
14
+ { name: '@x/ui', dir: fixture.path('node_modules/@x/ui') },
15
+ { name: 'app', dir: fixture.root, root: true },
16
+ ],
17
+ };
18
+ const writer = new OutputWriter(model, fixture.path('.cell/output'), 'esm');
19
+ afterAll(() => fixture.dispose());
20
+ it('finds the favicon and assets where copyFrontendFiles would take them from', () => {
21
+ expect(writer.frontendFile('/favicon.ico')).toBe(fixture.path('favicon.ico'));
22
+ expect(writer.frontendFile('/assets/logo.png')).toBe(fixture.path('src/browser/assets/logo.png'));
23
+ expect(writer.frontendFile('/assets/ui.css')).toBe(fixture.path('node_modules/@x/ui/assets/ui.css'));
24
+ // The copy does not overwrite, so the first component that has the file wins.
25
+ expect(writer.frontendFile('/assets/shared.txt')).toBe(fixture.path('node_modules/@x/ui/assets/shared.txt'));
26
+ });
27
+ it('finds nothing outside the asset directories', () => {
28
+ expect(writer.frontendFile('/assets/../../favicon.ico')).toBeUndefined();
29
+ expect(writer.frontendFile('/assets/missing.png')).toBeUndefined();
30
+ expect(writer.frontendFile('/assets/')).toBeUndefined();
31
+ expect(writer.frontendFile('/package.json')).toBeUndefined();
32
+ });
33
+ });
34
+ //# sourceMappingURL=output-writer.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-writer.spec.js","sourceRoot":"","sources":["../../src/output/output-writer.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACvC,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,sBAAsB,CAAC;SACrD,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC;SACnC,IAAI,CAAC,6BAA6B,EAAE,cAAc,CAAC;SACnD,IAAI,CAAC,+BAA+B,EAAE,SAAS,CAAC;SAChD,UAAU,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,mBAAmB,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;IACvF,MAAM,KAAK,GAAG;QACV,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,CAAC,UAAU,CAAC;QACrB,UAAU,EAAE;YACR,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,EAAE;YAC1D,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;SACjD;KACuB,CAAC;IAC7B,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,KAAK,CAAC,CAAC;IAE5E,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAElC,EAAE,CAAC,2EAA2E,EAAE,GAAG,EAAE;QACjF,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;QAC9E,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,CAAC;QAClG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC,CAAC;QACrG,8EAA8E;QAC9E,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC,CAAC;IACjH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACnD,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,2BAA2B,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QACzE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QACnE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QACxD,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IACjE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,134 @@
1
+ import { type ModuleRef, type ProjectModel, type ServerRuntime, type Target } from '@celljs/kit';
2
+ import type { ConfigEnv, Plugin, UserConfig, ViteBuilder } from 'vite';
3
+ import { ExpressionEvaluator } from '../expression/expression-evaluator.js';
4
+ import { OutputWriter } from '../output/output-writer.js';
5
+ import { type ProjectLoaderOptions } from '../project/project-loader.js';
6
+ import { NodePolyfills } from './node-polyfills.js';
7
+ export interface CellPluginOptions extends ProjectLoaderOptions {
8
+ /** Server bundle format. Default `esm` (`server/index.mjs`); `cjs` emits `server/index.cjs`. */
9
+ format?: 'esm' | 'cjs';
10
+ /** Output directory, relative to the project root. Default `.cell/output`. */
11
+ outDir?: string;
12
+ /** Packages the server bundle must not inline; they are copied into `server/node_modules`. */
13
+ external?: string[];
14
+ sourcemap?: boolean;
15
+ /** Name of the preset that chose the options, recorded in manifest.json. */
16
+ preset?: string;
17
+ /**
18
+ * Runtime of the server bundle. Default `node`. `workerd` (Cloudflare Workers) has no
19
+ * `import.meta.url` / `dirname` / `filename`: the bundle uses {@link WORKERD_SERVER_FILE} instead.
20
+ */
21
+ runtime?: ServerRuntime;
22
+ /**
23
+ * Embed the frontend in the server bundle (`cell build --single`): the server serves it from
24
+ * memory, and the output has no public directory. Only with both targets.
25
+ */
26
+ single?: boolean;
27
+ }
28
+ type ResolveContext = {
29
+ resolve(id: string, importer?: string, options?: {
30
+ skipSelf?: boolean;
31
+ }): Promise<{
32
+ id: string;
33
+ } | null>;
34
+ };
35
+ /**
36
+ * Turns the component graph into the DI container and configuration of each target and builds the
37
+ * `client` environment (frontend → `<outDir>/public`) and the `server` environment (backend, one
38
+ * file → `<outDir>/server`). Exposed to Vite through {@link cell}.
39
+ */
40
+ export declare class CellPlugin {
41
+ protected readonly options: CellPluginOptions;
42
+ protected model: ProjectModel;
43
+ protected root: string;
44
+ protected coreDir: string;
45
+ protected output: OutputWriter;
46
+ protected evaluator: ExpressionEvaluator;
47
+ protected polyfills: NodePolyfills;
48
+ protected command: ConfigEnv['command'];
49
+ protected readonly format: 'esm' | 'cjs';
50
+ constructor(options?: CellPluginOptions);
51
+ get project(): ProjectModel;
52
+ toVitePlugin(): Plugin;
53
+ /** The line `scripts/build-esm.ts` adds to ESM files of Cell packages that call `require`. */
54
+ static readonly REQUIRE_SHIM: RegExp;
55
+ /**
56
+ * Cell packages built as ES modules keep node-only `require('x')` calls working in Node through a
57
+ * local `const require = createRequire(import.meta.url)`. The bundler cannot see through that local
58
+ * binding, so the required packages would stay outside the bundle and be missing next to it. Drop
59
+ * the shim in the bundle: `require('x')` is then bundled like any other dependency.
60
+ */
61
+ static withoutRequireShim(code: string): string | null;
62
+ /**
63
+ * The module runner of `cell dev` evaluates sources as ES modules, which have no `require`; the
64
+ * bundler of `cell build` accepts `require('x')` next to `import`. Give TypeScript and JavaScript
65
+ * sources outside node_modules that call `require(` a module-local one, as the ESM builds of
66
+ * Cell packages have.
67
+ */
68
+ static withRequire(code: string, id: string): string | null;
69
+ /**
70
+ * CommonJS files of the project (generated clients like prisma's) cannot run as ES modules in the
71
+ * module runner of `cell dev`. Node loads them instead, in the same process, and the module
72
+ * re-exports what they export.
73
+ */
74
+ static commonJsWrapper(id: string): string | null;
75
+ static isCommonJsFile(file: string): boolean;
76
+ /**
77
+ * CommonJS libraries bundled into the ESM server expect what a CommonJS server gives them: a
78
+ * `require` in scope (prisma loads its engine with `eval('require')`) and `require.main` (app-root-path,
79
+ * used by typeorm, reads `require.main.filename`). Expose the bundle's `__require` as `require`, with
80
+ * the bundle itself as the main module.
81
+ */
82
+ static withCommonJsGlobals(code: string, runtime?: ServerRuntime): string | null;
83
+ /**
84
+ * `import.meta.dirname` / `filename` exist from Node.js 20.11; the Node.js of FC (20.10) and SCF (18)
85
+ * lack them, so the bundle sets them from `import.meta.url` when they are missing.
86
+ */
87
+ static withImportMetaPaths(code: string): string;
88
+ /**
89
+ * How the server bundle refers to its own location: `import.meta` on Node.js; fixed paths under
90
+ * `/bundle` on workerd, which leaves `import.meta.url` undefined (`createRequire` then throws).
91
+ */
92
+ static importMeta(runtime?: ServerRuntime): {
93
+ url: string;
94
+ dirname: string;
95
+ filename: string;
96
+ };
97
+ protected config(userConfig: UserConfig, env: ConfigEnv): UserConfig;
98
+ /**
99
+ * `cell dev`: the client environment serves the frontend with HMR, the server environment runs the
100
+ * backend in a module runner. Cell packages go through the plugin in both (they must see the
101
+ * generated container and configuration, and share one @celljs/core); other dependencies stay
102
+ * in node_modules: pre-bundled for the browser, loaded by Node for the server.
103
+ */
104
+ protected devConfig(nodeEnv: string): UserConfig;
105
+ /** Components of the project other than itself. */
106
+ protected get componentNames(): string[];
107
+ /** A file of the public directory that is copied, not built (favicon, component assets); see {@link OutputWriter.frontendFile}. */
108
+ frontendFile(path: string): string | undefined;
109
+ /** The page of the frontend: the project's index.html or the built-in one, with the frontend configuration applied. */
110
+ renderHtml(): string;
111
+ /** `--single` with a frontend and a backend: the frontend goes into the server bundle. */
112
+ protected get single(): boolean;
113
+ /** Builds the targets of the project (the frontend first, as a single server embeds it), then writes the files around the bundles. */
114
+ protected buildApp(builder: ViteBuilder): Promise<void>;
115
+ protected resolveId(ctx: ResolveContext, environment: string, id: string, importer?: string): string | Promise<{
116
+ id: string;
117
+ } | null> | null;
118
+ protected load(ctx: ResolveContext, environment: string, id: string): Promise<string | null>;
119
+ protected resolveModules(ctx: ResolveContext, target: Target, refs: ModuleRef[]): Promise<string[]>;
120
+ /**
121
+ * CommonJS dependencies inlined into an ES module bundle still reference the free `__dirname` and
122
+ * `__filename`; point them at the bundle file, as a CommonJS bundle would.
123
+ */
124
+ protected serverDefines(nodeEnv: string): Record<string, string>;
125
+ protected get htmlFile(): string;
126
+ protected get externals(): string[];
127
+ protected isExternal(id: string): boolean;
128
+ protected isCoreFile(id: string, path: string): boolean;
129
+ protected resolveCoreDir(): string;
130
+ }
131
+ /** The Cell Vite plugin: `plugins: [cell()]` in vite.config.ts, then `vite build`. */
132
+ export declare function cell(options?: CellPluginOptions): Plugin;
133
+ export {};
134
+ //# sourceMappingURL=cell-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell-plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/cell-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,KAAK,SA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