paralayer 1.8.0 → 1.10.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.
package/dist/bin.js CHANGED
@@ -32,8 +32,6 @@ var Paralayer = class extends Unit {
32
32
  await this.ready$.promise;
33
33
  await this.queue.run(() => this.build());
34
34
  if (!this.options.watch) await this.watcher.close();
35
- }
36
- async readSetupJs() {
37
35
  const setupJsPath = join(this.options.output, "setup.js");
38
36
  return await readFile(setupJsPath, "utf-8");
39
37
  }
@@ -133,7 +131,7 @@ var Paralayer = class extends Unit {
133
131
  }
134
132
  const globals = [
135
133
  `declare global {`,
136
- ` var ${layerName}: ${LayerName}`,
134
+ ` const ${layerName}: ${LayerName}`,
137
135
  ``,
138
136
  ` interface ${LayerName} ${extendPascal}{`,
139
137
  ...allNames.map((name) => ` ${name}: typeof ${name}`),
@@ -155,6 +153,9 @@ var Paralayer = class extends Unit {
155
153
  if (layer1.length !== layer2.length) return layer2.length - layer1.length;
156
154
  return layer1.localeCompare(layer2);
157
155
  }).map((layer) => `import './layer.${layer}.ts'`);
156
+ if (this.options.globalLayerName && topLayer !== this.options.globalLayerName) {
157
+ imports.unshift(`import './layer.${this.options.globalLayerName}.ts'`);
158
+ }
158
159
  return [...imports].join("\n");
159
160
  }
160
161
  generateSetupContent(allLayers) {
@@ -197,9 +198,8 @@ var Paralayer = class extends Unit {
197
198
  }
198
199
  };
199
200
  async function paralayer(options) {
200
- const pl = new Paralayer(options);
201
- await pl.start();
202
- return await pl.readSetupJs();
201
+ const setupLayersJs = await new Paralayer(options).start();
202
+ return setupLayersJs;
203
203
  }
204
204
 
205
205
  // src/bin.ts
@@ -13,7 +13,7 @@ type Options = {
13
13
  globalize?: boolean;
14
14
  /** If provided, other layers will extend this layer. */
15
15
  globalLayerName?: string | null;
16
- /** If a file name does not have layer tags, default layer name will be used. */
16
+ /** If a file name does not have any layer tags, default layer name will be used. */
17
17
  defaultLayerName?: string | null;
18
18
  };
19
19
  declare class Paralayer extends Unit {
@@ -27,8 +27,7 @@ declare class Paralayer extends Unit {
27
27
  private previousLayers;
28
28
  private watcher;
29
29
  constructor(options: Options);
30
- start(): Promise<void>;
31
- readSetupJs(): Promise<string>;
30
+ start(): Promise<string | undefined>;
32
31
  private onAll;
33
32
  private onReady;
34
33
  private build;
@@ -43,6 +42,6 @@ declare class Paralayer extends Unit {
43
42
  private isTopLayer;
44
43
  private write;
45
44
  }
46
- declare function paralayer(options: Options): Promise<string>;
45
+ declare function paralayer(options: Options): Promise<string | undefined>;
47
46
 
48
47
  export { type DirPath, type File, type Options, Paralayer, paralayer as default, paralayer };
package/dist/paralayer.js CHANGED
@@ -27,8 +27,6 @@ var Paralayer = class extends Unit {
27
27
  await this.ready$.promise;
28
28
  await this.queue.run(() => this.build());
29
29
  if (!this.options.watch) await this.watcher.close();
30
- }
31
- async readSetupJs() {
32
30
  const setupJsPath = join(this.options.output, "setup.js");
33
31
  return await readFile(setupJsPath, "utf-8");
34
32
  }
@@ -128,7 +126,7 @@ var Paralayer = class extends Unit {
128
126
  }
129
127
  const globals = [
130
128
  `declare global {`,
131
- ` var ${layerName}: ${LayerName}`,
129
+ ` const ${layerName}: ${LayerName}`,
132
130
  ``,
133
131
  ` interface ${LayerName} ${extendPascal}{`,
134
132
  ...allNames.map((name) => ` ${name}: typeof ${name}`),
@@ -150,6 +148,9 @@ var Paralayer = class extends Unit {
150
148
  if (layer1.length !== layer2.length) return layer2.length - layer1.length;
151
149
  return layer1.localeCompare(layer2);
152
150
  }).map((layer) => `import './layer.${layer}.ts'`);
151
+ if (this.options.globalLayerName && topLayer !== this.options.globalLayerName) {
152
+ imports.unshift(`import './layer.${this.options.globalLayerName}.ts'`);
153
+ }
153
154
  return [...imports].join("\n");
154
155
  }
155
156
  generateSetupContent(allLayers) {
@@ -192,9 +193,8 @@ var Paralayer = class extends Unit {
192
193
  }
193
194
  };
194
195
  async function paralayer(options) {
195
- const pl = new Paralayer(options);
196
- await pl.start();
197
- return await pl.readSetupJs();
196
+ const setupLayersJs = await new Paralayer(options).start();
197
+ return setupLayersJs;
198
198
  }
199
199
  var paralayer_default = paralayer;
200
200
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paralayer",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "imkost",
@@ -23,6 +23,9 @@
23
23
  "source": "./src/paralayer.ts",
24
24
  "import": "./dist/paralayer.js",
25
25
  "types": "./dist/paralayer.d.ts"
26
+ },
27
+ "./ts": {
28
+ "import": "./src/paralayer.ts"
26
29
  }
27
30
  },
28
31
  "files": [
@@ -30,7 +33,7 @@
30
33
  "dist"
31
34
  ],
32
35
  "dependencies": {
33
- "@eposlabs/utils": "^1.9.0",
36
+ "@eposlabs/utils": "^1.10.0",
34
37
  "chokidar": "^4.0.3",
35
38
  "minimist": "^1.2.8"
36
39
  },
package/src/paralayer.ts CHANGED
@@ -19,7 +19,7 @@ export type Options = {
19
19
  globalize?: boolean
20
20
  /** If provided, other layers will extend this layer. */
21
21
  globalLayerName?: string | null
22
- /** If a file name does not have layer tags, default layer name will be used. */
22
+ /** If a file name does not have any layer tags, default layer name will be used. */
23
23
  defaultLayerName?: string | null
24
24
  }
25
25
 
@@ -52,9 +52,8 @@ export class Paralayer extends Unit {
52
52
  await this.ready$.promise
53
53
  await this.queue.run(() => this.build())
54
54
  if (!this.options.watch) await this.watcher.close()
55
- }
56
55
 
57
- async readSetupJs() {
56
+ // Return content of setup.js
58
57
  const setupJsPath = join(this.options.output, 'setup.js')
59
58
  return await readFile(setupJsPath, 'utf-8')
60
59
  }
@@ -201,7 +200,7 @@ export class Paralayer extends Unit {
201
200
 
202
201
  const globals = [
203
202
  `declare global {`,
204
- ` var ${layerName}: ${LayerName}`,
203
+ ` const ${layerName}: ${LayerName}`,
205
204
  ``,
206
205
  ` interface ${LayerName} ${extendPascal}{`,
207
206
  ...allNames.map(name => ` ${name}: typeof ${name}`),
@@ -229,6 +228,10 @@ export class Paralayer extends Unit {
229
228
  })
230
229
  .map(layer => `import './layer.${layer}.ts'`)
231
230
 
231
+ if (this.options.globalLayerName && topLayer !== this.options.globalLayerName) {
232
+ imports.unshift(`import './layer.${this.options.globalLayerName}.ts'`)
233
+ }
234
+
232
235
  return [...imports].join('\n')
233
236
  }
234
237
 
@@ -281,9 +284,8 @@ export class Paralayer extends Unit {
281
284
  }
282
285
 
283
286
  export async function paralayer(options: Options) {
284
- const pl = new Paralayer(options)
285
- await pl.start()
286
- return await pl.readSetupJs()
287
+ const setupLayersJs = await new Paralayer(options).start()
288
+ return setupLayersJs
287
289
  }
288
290
 
289
291
  export default paralayer