@decohere/forge 0.0.1-dev.110 → 0.0.1-dev.111

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.
@@ -25,6 +25,9 @@ class BuildCommand extends _cli.DecohereCommand {
25
25
  this.option("--watch", "Watches for changes in the source dir", false);
26
26
  this.option("--file <file>", "File to build");
27
27
  }
28
+ runsUntilStopped(options) {
29
+ return options.watch === true;
30
+ }
28
31
  run = async (actions, options)=>{
29
32
  const responses = await (0, _auto.default)({
30
33
  clean: async ()=>await actions.clean.run(options),
@@ -49,6 +49,9 @@ class LinkCommand extends _cli.DecohereCommand {
49
49
  this.option("--target-dir <dir>", "Path to the consumer project root");
50
50
  this.option("--watch", "Watch for changes after linking", false);
51
51
  }
52
+ runsUntilStopped(options) {
53
+ return options.watch === true;
54
+ }
52
55
  run = async (actions, options)=>{
53
56
  const responses = await (0, _auto.default)({
54
57
  clean: async ()=>await actions.clean.run(options),
@@ -114,29 +114,31 @@ class SwcTranspiler extends (0, _extensibility.mixwith)(_cachesoutputsmixin.Cach
114
114
  config: swcOptions
115
115
  });
116
116
  }
117
- if (content === "") {
118
- return _transformresponsemodel.TransformResponse.Skipped({
119
- file,
120
- messages: "File is empty",
121
- config: swcOptions
122
- });
123
- }
117
+ if (content === "") return SwcTranspiler.skippedEmpty(file, swcOptions);
124
118
  try {
125
119
  const transformed = (0, _core.transformSync)(content, swcOptions);
126
120
  if (transformed == null) {
127
121
  throw new Error("swc.transformSync returned no result");
128
122
  }
129
- const filePath = file.relativePath;
130
- const extName = _nodepath.default.extname(filePath);
131
- const fileName = filePath.replace(new RegExp(`${extName}$`), ".js");
132
- return _transformresponsemodel.TransformResponse.Success({
123
+ return SwcTranspiler.succeeded(file, buildTarget, swcOptions, content, transformed.code);
124
+ } catch (error) {
125
+ return _transformresponsemodel.TransformResponse.Error({
133
126
  file,
134
- code: transformed.code,
135
- sourceContent: content,
136
- target: buildTarget,
137
- fileName,
127
+ messages: [
128
+ String(error)
129
+ ],
138
130
  config: swcOptions
139
131
  });
132
+ }
133
+ }
134
+ /**
135
+ * Async variant of {@link transformFileSync}, with the same result for the same file. SWC
136
+ * runs it on libuv's thread pool, so many calls in flight compile in parallel (#661).
137
+ */ async transformFileAsync(file, buildTarget, options = {}, baseConfig = this.createBaseConfig(buildTarget, options)) {
138
+ const swcOptions = this.#swcConfigFactory.createFileConfig(file, baseConfig);
139
+ let content;
140
+ try {
141
+ content = await _nodefs.default.promises.readFile(file.fullPath, "utf8");
140
142
  } catch (error) {
141
143
  return _transformresponsemodel.TransformResponse.Error({
142
144
  file,
@@ -146,6 +148,42 @@ class SwcTranspiler extends (0, _extensibility.mixwith)(_cachesoutputsmixin.Cach
146
148
  config: swcOptions
147
149
  });
148
150
  }
151
+ if (content === "") return SwcTranspiler.skippedEmpty(file, swcOptions);
152
+ try {
153
+ const transformed = await (0, _core.transform)(content, swcOptions);
154
+ if (transformed == null) {
155
+ throw new Error("swc.transform returned no result");
156
+ }
157
+ return SwcTranspiler.succeeded(file, buildTarget, swcOptions, content, transformed.code);
158
+ } catch (error) {
159
+ return _transformresponsemodel.TransformResponse.Error({
160
+ file,
161
+ messages: [
162
+ String(error)
163
+ ],
164
+ config: swcOptions
165
+ });
166
+ }
167
+ }
168
+ static skippedEmpty(file, swcOptions) {
169
+ return _transformresponsemodel.TransformResponse.Skipped({
170
+ file,
171
+ messages: "File is empty",
172
+ config: swcOptions
173
+ });
174
+ }
175
+ static succeeded(file, buildTarget, swcOptions, content, code) {
176
+ const filePath = file.relativePath;
177
+ const extName = _nodepath.default.extname(filePath);
178
+ const fileName = filePath.replace(new RegExp(`${extName}$`), ".js");
179
+ return _transformresponsemodel.TransformResponse.Success({
180
+ file,
181
+ code,
182
+ sourceContent: content,
183
+ target: buildTarget,
184
+ fileName,
185
+ config: swcOptions
186
+ });
149
187
  }
150
188
  async transformTarget(files, buildTarget, options, project, onOutput) {
151
189
  const baseConfig = this.#swcConfigFactory.createBaseConfig(buildTarget, this.withAliasContext(options));
@@ -10,6 +10,9 @@ export class BuildCommand extends DecohereCommand {
10
10
  this.option("--watch", "Watches for changes in the source dir", false);
11
11
  this.option("--file <file>", "File to build");
12
12
  }
13
+ runsUntilStopped(options) {
14
+ return options.watch === true;
15
+ }
13
16
  run = async (actions, options)=>{
14
17
  const responses = await auto({
15
18
  clean: async ()=>await actions.clean.run(options),
@@ -26,6 +26,9 @@ export class LinkCommand extends DecohereCommand {
26
26
  this.option("--target-dir <dir>", "Path to the consumer project root");
27
27
  this.option("--watch", "Watch for changes after linking", false);
28
28
  }
29
+ runsUntilStopped(options) {
30
+ return options.watch === true;
31
+ }
29
32
  run = async (actions, options)=>{
30
33
  const responses = await auto({
31
34
  clean: async ()=>await actions.clean.run(options),
@@ -99,29 +99,31 @@ export class SwcTranspiler extends mixwith(CachesOutputs, IncrementalTransform)
99
99
  config: swcOptions
100
100
  });
101
101
  }
102
- if (content === "") {
103
- return TransformResponse.Skipped({
104
- file,
105
- messages: "File is empty",
106
- config: swcOptions
107
- });
108
- }
102
+ if (content === "") return SwcTranspiler.skippedEmpty(file, swcOptions);
109
103
  try {
110
104
  const transformed = transformSync(content, swcOptions);
111
105
  if (transformed == null) {
112
106
  throw new Error("swc.transformSync returned no result");
113
107
  }
114
- const filePath = file.relativePath;
115
- const extName = path.extname(filePath);
116
- const fileName = filePath.replace(new RegExp(`${extName}$`), ".js");
117
- return TransformResponse.Success({
108
+ return SwcTranspiler.succeeded(file, buildTarget, swcOptions, content, transformed.code);
109
+ } catch (error) {
110
+ return TransformResponse.Error({
118
111
  file,
119
- code: transformed.code,
120
- sourceContent: content,
121
- target: buildTarget,
122
- fileName,
112
+ messages: [
113
+ String(error)
114
+ ],
123
115
  config: swcOptions
124
116
  });
117
+ }
118
+ }
119
+ /**
120
+ * Async variant of {@link transformFileSync}, with the same result for the same file. SWC
121
+ * runs it on libuv's thread pool, so many calls in flight compile in parallel (#661).
122
+ */ async transformFileAsync(file, buildTarget, options = {}, baseConfig = this.createBaseConfig(buildTarget, options)) {
123
+ const swcOptions = this.#swcConfigFactory.createFileConfig(file, baseConfig);
124
+ let content;
125
+ try {
126
+ content = await fs.promises.readFile(file.fullPath, "utf8");
125
127
  } catch (error) {
126
128
  return TransformResponse.Error({
127
129
  file,
@@ -131,6 +133,42 @@ export class SwcTranspiler extends mixwith(CachesOutputs, IncrementalTransform)
131
133
  config: swcOptions
132
134
  });
133
135
  }
136
+ if (content === "") return SwcTranspiler.skippedEmpty(file, swcOptions);
137
+ try {
138
+ const transformed = await transform(content, swcOptions);
139
+ if (transformed == null) {
140
+ throw new Error("swc.transform returned no result");
141
+ }
142
+ return SwcTranspiler.succeeded(file, buildTarget, swcOptions, content, transformed.code);
143
+ } catch (error) {
144
+ return TransformResponse.Error({
145
+ file,
146
+ messages: [
147
+ String(error)
148
+ ],
149
+ config: swcOptions
150
+ });
151
+ }
152
+ }
153
+ static skippedEmpty(file, swcOptions) {
154
+ return TransformResponse.Skipped({
155
+ file,
156
+ messages: "File is empty",
157
+ config: swcOptions
158
+ });
159
+ }
160
+ static succeeded(file, buildTarget, swcOptions, content, code) {
161
+ const filePath = file.relativePath;
162
+ const extName = path.extname(filePath);
163
+ const fileName = filePath.replace(new RegExp(`${extName}$`), ".js");
164
+ return TransformResponse.Success({
165
+ file,
166
+ code,
167
+ sourceContent: content,
168
+ target: buildTarget,
169
+ fileName,
170
+ config: swcOptions
171
+ });
134
172
  }
135
173
  async transformTarget(files, buildTarget, options, project, onOutput) {
136
174
  const baseConfig = this.#swcConfigFactory.createBaseConfig(buildTarget, this.withAliasContext(options));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decohere/forge",
3
- "version": "0.0.1-dev.110",
3
+ "version": "0.0.1-dev.111",
4
4
  "description": "TypeScript monorepo build system — zero config, fast compilation, streamlined developer workflow",
5
5
  "keywords": [
6
6
  "typescript",
@@ -29,10 +29,10 @@
29
29
  "test": "echo \"Error: no test specified\" && exit 1"
30
30
  },
31
31
  "dependencies": {
32
- "@decohere/crucible": "0.0.1-dev.110",
33
- "@decohere/mesh": "0.0.1-dev.110",
34
- "@decohere/nexus": "0.0.1-dev.110",
35
- "@decohere/scribe": "0.0.1-dev.110",
32
+ "@decohere/crucible": "0.0.1-dev.111",
33
+ "@decohere/mesh": "0.0.1-dev.111",
34
+ "@decohere/nexus": "0.0.1-dev.111",
35
+ "@decohere/scribe": "0.0.1-dev.111",
36
36
  "@swc/core": "^1.11.11",
37
37
  "async": "^3.2.6",
38
38
  "parse-imports": "^2.2.1",
@@ -12,5 +12,6 @@ export type BuildActions = {
12
12
  };
13
13
  export declare class BuildCommand extends DecohereCommand<BuildActions> {
14
14
  constructor(name?: string);
15
+ runsUntilStopped(options: Record<string, unknown>): boolean;
15
16
  run: (actions: BuildActions, options: MergeOptions<BuildActions>) => Promise<CommandResponse<BuildActions>>;
16
17
  }
@@ -19,6 +19,7 @@ type UnlinkActions = {
19
19
  export declare class LinkCommand extends DecohereCommand<LinkActions> {
20
20
  get actions(): (typeof Build | typeof Clean | typeof Copy | typeof Link | typeof Watch)[];
21
21
  constructor(name?: string);
22
+ runsUntilStopped(options: Record<string, unknown>): boolean;
22
23
  run: (actions: LinkActions, options: MergeOptions<LinkActions>) => Promise<CommandResponse<LinkActions>>;
23
24
  }
24
25
  export declare class UnlinkCommand extends DecohereCommand<UnlinkActions> {
@@ -37,6 +37,13 @@ export declare class SwcTranspiler extends SwcTranspiler_base implements Transfo
37
37
  * Pass `baseConfig` from {@link createBaseConfig} to skip rebuilding it for every file.
38
38
  */
39
39
  transformFileSync(file: FileEx, buildTarget: TranspileTarget, options?: TranspileOptions, baseConfig?: Options): TransformResponse;
40
+ /**
41
+ * Async variant of {@link transformFileSync}, with the same result for the same file. SWC
42
+ * runs it on libuv's thread pool, so many calls in flight compile in parallel (#661).
43
+ */
44
+ transformFileAsync(file: FileEx, buildTarget: TranspileTarget, options?: TranspileOptions, baseConfig?: Options): Promise<TransformResponse>;
45
+ private static skippedEmpty;
46
+ private static succeeded;
40
47
  private transformTarget;
41
48
  private runTransform;
42
49
  protected onIncrementalFileEvent(evt: ProjectFileEvent): Promise<TransformResponse[]>;