vite-plugin-taro 0.6.0 → 0.6.2

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 (68) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/node/plugins/h5/transform-app.js +1 -1
  4. package/dist/node/plugins/wx/dev/plugins.js +1 -1
  5. package/dist/node/plugins/wx/dev/wx-dev-options.js +22 -1
  6. package/dist/node/plugins/wx/module/chunk-path.d.ts +8 -0
  7. package/dist/node/plugins/wx/module/chunk-path.js +18 -0
  8. package/dist/node/plugins/wx/{module.js → module/module.js} +2 -2
  9. package/dist/node/plugins/wx/native/create-native-component-output.d.ts +3 -1
  10. package/dist/node/plugins/wx/native/create-native-component-output.js +3 -5
  11. package/dist/node/plugins/wx/output/files.d.ts +3 -2
  12. package/dist/node/plugins/wx/output/files.js +2 -2
  13. package/dist/node/plugins/wx/output/json.d.ts +1 -1
  14. package/dist/node/plugins/wx/output/json.js +1 -1
  15. package/dist/node/plugins/wx/placer/placement.d.ts +51 -0
  16. package/dist/node/plugins/wx/placer/placement.js +245 -0
  17. package/dist/node/plugins/wx/placer/placer.d.ts +76 -0
  18. package/dist/node/plugins/wx/placer/placer.js +147 -0
  19. package/dist/node/plugins/wx/plugins.js +17 -17
  20. package/dist/node/plugins/wx/render/capsule.d.ts +35 -3
  21. package/dist/node/plugins/wx/render/capsule.js +53 -12
  22. package/dist/node/plugins/wx/render/native.d.ts +20 -2
  23. package/dist/node/plugins/wx/render/native.js +539 -35
  24. package/dist/node/plugins/wx/render/system-js/string-editor.d.ts +24 -0
  25. package/dist/node/plugins/wx/render/system-js/string-editor.js +93 -0
  26. package/dist/node/plugins/wx/render/system-js/system-js.d.ts +23 -0
  27. package/dist/node/plugins/wx/render/system-js/system-js.js +602 -0
  28. package/dist/node/plugins/wx/render/transport.d.ts +7 -3
  29. package/dist/node/plugins/wx/render/transport.js +19 -10
  30. package/dist/node/plugins/wx/resolve/resolver.js +1 -1
  31. package/dist/node/plugins/wx/resolve/specialize-bootstrap.js +1 -1
  32. package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +1 -1
  33. package/dist/node/utils/modules.d.ts +0 -2
  34. package/dist/node/utils/modules.js +0 -7
  35. package/dist/node/utils/transform.d.ts +0 -3
  36. package/dist/node/utils/transform.js +0 -23
  37. package/package.json +8 -6
  38. package/src/node/plugins/h5/transform-app.ts +1 -1
  39. package/src/node/plugins/wx/dev/plugins.ts +1 -1
  40. package/src/node/plugins/wx/dev/wx-dev-options.ts +22 -1
  41. package/src/node/plugins/wx/module/chunk-path.ts +22 -0
  42. package/src/node/plugins/wx/{module.ts → module/module.ts} +2 -2
  43. package/src/node/plugins/wx/native/create-native-component-output.ts +6 -5
  44. package/src/node/plugins/wx/output/files.ts +5 -3
  45. package/src/node/plugins/wx/output/json.ts +1 -2
  46. package/src/node/plugins/wx/placer/placement.ts +364 -0
  47. package/src/node/plugins/wx/placer/placer.ts +179 -0
  48. package/src/node/plugins/wx/plugins.ts +19 -19
  49. package/src/node/plugins/wx/render/capsule.ts +53 -17
  50. package/src/node/plugins/wx/render/native.ts +670 -55
  51. package/src/node/plugins/wx/render/system-js/string-editor.ts +115 -0
  52. package/src/node/plugins/wx/render/system-js/system-js.ts +831 -0
  53. package/src/node/plugins/wx/render/transport.ts +25 -9
  54. package/src/node/plugins/wx/resolve/resolver.ts +1 -1
  55. package/src/node/plugins/wx/resolve/specialize-bootstrap.ts +1 -1
  56. package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +1 -1
  57. package/src/node/utils/modules.ts +0 -8
  58. package/src/node/utils/transform.ts +0 -30
  59. package/dist/node/plugins/wx/placement/placer.d.ts +0 -78
  60. package/dist/node/plugins/wx/placement/placer.js +0 -158
  61. package/dist/node/plugins/wx/placement/plan.d.ts +0 -46
  62. package/dist/node/plugins/wx/placement/plan.js +0 -210
  63. package/dist/node/plugins/wx/render/capsule-wrapper.d.ts +0 -3
  64. package/dist/node/plugins/wx/render/capsule-wrapper.js +0 -64
  65. package/src/node/plugins/wx/placement/placer.ts +0 -187
  66. package/src/node/plugins/wx/placement/plan.ts +0 -306
  67. package/src/node/plugins/wx/render/capsule-wrapper.ts +0 -86
  68. /package/dist/node/plugins/wx/{module.d.ts → module/module.d.ts} +0 -0
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Records non-overlapping range edits and renders them in one source-order pass.
3
+ *
4
+ * Final WX development chunks do not request source maps. RolldownMagicString's repeated relocation of hundreds of hoisted
5
+ * functions is considerably more expensive than the semantic analysis itself, so this editor keeps the same range operations
6
+ * while avoiding a mutable chunk graph when no mappings can be observed.
7
+ */
8
+ export class StringEditor {
9
+ original;
10
+ // These journals are the editor's intentionally mutable transaction; rendering reads but never changes them.
11
+ #insertions = new Map();
12
+ #replacements = [];
13
+ constructor(original) {
14
+ this.original = original;
15
+ }
16
+ /** Records a half-open replacement; semantic passes guarantee ranges are nested or disjoint. */
17
+ overwrite(start, end, content) {
18
+ this.#replacements.push({ content, end, start });
19
+ }
20
+ /** Removes a range and discards insertions that were owned only by that removed source. */
21
+ remove(start, end) {
22
+ this.overwrite(start, end, '');
23
+ // Removed ranges own their boundary insertions; hoisted function text has already rendered those edits separately.
24
+ for (const position of this.#insertions.keys()) {
25
+ if (position >= start && position <= end)
26
+ this.#insertions.delete(position);
27
+ }
28
+ }
29
+ /** Inserts before prior insertions at a boundary, matching MagicString's prependLeft ordering. */
30
+ prependLeft(position, content) {
31
+ const insertions = this.#insertionAt(position);
32
+ insertions.prepend.unshift(content);
33
+ }
34
+ /** Inserts after prior insertions at the left side of a boundary. */
35
+ appendLeft(position, content) {
36
+ const insertions = this.#insertionAt(position);
37
+ insertions.append.push(content);
38
+ }
39
+ /** Matches the subset of appendRight ordering used by the capsule compiler. */
40
+ appendRight(position, content) {
41
+ const insertions = this.#insertionAt(position);
42
+ insertions.append.push(content);
43
+ }
44
+ /** Materializes one source slice without mutating its edit journal, allowing functions to be rendered before relocation. */
45
+ render(start, end) {
46
+ const replacements = this.#replacements
47
+ .filter((replacement) => replacement.start >= start && replacement.end <= end)
48
+ .sort((left, right) => left.start - right.start || right.end - left.end);
49
+ // The cursor advances monotonically; outer removals dominate nested edits when hoisted function ranges are removed.
50
+ let sourcePosition = start;
51
+ let output = '';
52
+ for (const replacement of replacements) {
53
+ if (replacement.end <= sourcePosition)
54
+ continue;
55
+ if (replacement.start < sourcePosition) {
56
+ throw new Error(`Partially overlapping source edits at ${replacement.start}:${replacement.end}`);
57
+ }
58
+ output += this.#renderOriginal(sourcePosition, replacement.start, false);
59
+ output += replacement.content;
60
+ sourcePosition = replacement.end;
61
+ }
62
+ output += this.#renderOriginal(sourcePosition, end, true);
63
+ return output;
64
+ }
65
+ #insertionAt(position) {
66
+ const existing = this.#insertions.get(position);
67
+ if (existing)
68
+ return existing;
69
+ // Each position owns mutable ordered lists because prependLeft reverses calls while appendRight preserves them.
70
+ const created = { append: [], prepend: [] };
71
+ this.#insertions.set(position, created);
72
+ return created;
73
+ }
74
+ #renderOriginal(start, end, includeEnd) {
75
+ const positions = [...this.#insertions.keys()]
76
+ .filter((position) => position >= start && (position < end || (includeEnd && position === end)))
77
+ .sort((left, right) => left - right);
78
+ // Segment rendering appends immutable source slices around the small ordered insertion set.
79
+ let sourcePosition = start;
80
+ let output = '';
81
+ for (const position of positions) {
82
+ output += this.original.slice(sourcePosition, position);
83
+ output += this.#renderInsertions(position);
84
+ sourcePosition = position;
85
+ }
86
+ output += this.original.slice(sourcePosition, end);
87
+ return output;
88
+ }
89
+ #renderInsertions(position) {
90
+ const insertions = this.#insertions.get(position);
91
+ return insertions ? `${insertions.prepend.join('')}${insertions.append.join('')}` : '';
92
+ }
93
+ }
@@ -0,0 +1,23 @@
1
+ import { type ExistingRawSourceMap } from 'rolldown';
2
+ export type SystemJsOutputFormat = 'system-register' | 'commonjs-registration';
3
+ export type SystemJsReferenceKind = 'static' | 'dynamic';
4
+ export type TransformSystemJsOptions = Readonly<{
5
+ /** Final JavaScript emitted by Rolldown with ES module syntax still present. */
6
+ code: string;
7
+ filename: string;
8
+ format: SystemJsOutputFormat;
9
+ sourcemap: boolean;
10
+ /** Converts physical Rolldown references into the logical IDs used by the WX capsule registry. */
11
+ resolveReference(reference: string, kind: SystemJsReferenceKind): string;
12
+ }>;
13
+ export type TransformSystemJsResult = Readonly<{
14
+ code: string;
15
+ map: ExistingRawSourceMap | null;
16
+ }>;
17
+ /**
18
+ * Converts one final Rolldown ES chunk into System.register data without rebuilding its complete AST through Babel.
19
+ *
20
+ * The compiler intentionally accepts Rolldown's normalized final-chunk grammar rather than arbitrary source modules. Every
21
+ * unsupported module declaration fails before source edits begin, so a future Rolldown output change cannot be miscompiled.
22
+ */
23
+ export declare function transformSystemJs(options: TransformSystemJsOptions): TransformSystemJsResult;