paralayer 1.9.0 → 1.11.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
@@ -4,8 +4,8 @@
4
4
  import minimist from "minimist";
5
5
 
6
6
  // src/paralayer.ts
7
- import { Queue, Unit, safe } from "@eposlabs/utils";
8
7
  import { watch } from "chokidar";
8
+ import { Queue, Unit, safe } from "dropcap/utils";
9
9
  import { mkdir, readFile, rm, writeFile } from "fs/promises";
10
10
  import { basename, extname, join, relative } from "path";
11
11
  var Paralayer = class extends Unit {
@@ -30,10 +30,8 @@ var Paralayer = class extends Unit {
30
30
  this.watcher.on("all", this.onAll);
31
31
  this.watcher.on("ready", this.onReady);
32
32
  await this.ready$.promise;
33
- await this.queue.run(() => this.build());
33
+ await this.queue.add(() => 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
  }
@@ -51,11 +49,11 @@ var Paralayer = class extends Unit {
51
49
  }
52
50
  if (event === "unlink") {
53
51
  delete this.files[path];
54
- await this.queue.run(() => this.build());
52
+ await this.queue.add(() => this.build());
55
53
  }
56
54
  if (event === "add" || event === "change") {
57
55
  this.files[path] = null;
58
- await this.queue.run(() => this.build());
56
+ await this.queue.add(() => this.build());
59
57
  }
60
58
  };
61
59
  onReady = async () => {
@@ -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}`),
@@ -182,7 +180,7 @@ var Paralayer = class extends Unit {
182
180
  const LayerName = layer.split(".").map(this.capitalize).join("");
183
181
  if (style === "camel") return this.decapitalize(LayerName);
184
182
  if (style === "Pascal") return LayerName;
185
- throw this.never;
183
+ throw this.never();
186
184
  }
187
185
  capitalize(string) {
188
186
  return string.charAt(0).toUpperCase() + string.slice(1);
@@ -200,9 +198,8 @@ var Paralayer = class extends Unit {
200
198
  }
201
199
  };
202
200
  async function paralayer(options) {
203
- const pl = new Paralayer(options);
204
- await pl.start();
205
- return await pl.readSetupJs();
201
+ const setupLayersJs = await new Paralayer(options).start();
202
+ return setupLayersJs;
206
203
  }
207
204
 
208
205
  // src/bin.ts
@@ -1,4 +1,4 @@
1
- import { Unit } from '@eposlabs/utils';
1
+ import { Unit } from 'dropcap/utils';
2
2
 
3
3
  type DirPath = string;
4
4
  type File = {
@@ -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
@@ -1,6 +1,6 @@
1
1
  // src/paralayer.ts
2
- import { Queue, Unit, safe } from "@eposlabs/utils";
3
2
  import { watch } from "chokidar";
3
+ import { Queue, Unit, safe } from "dropcap/utils";
4
4
  import { mkdir, readFile, rm, writeFile } from "fs/promises";
5
5
  import { basename, extname, join, relative } from "path";
6
6
  var Paralayer = class extends Unit {
@@ -25,10 +25,8 @@ var Paralayer = class extends Unit {
25
25
  this.watcher.on("all", this.onAll);
26
26
  this.watcher.on("ready", this.onReady);
27
27
  await this.ready$.promise;
28
- await this.queue.run(() => this.build());
28
+ await this.queue.add(() => 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
  }
@@ -46,11 +44,11 @@ var Paralayer = class extends Unit {
46
44
  }
47
45
  if (event === "unlink") {
48
46
  delete this.files[path];
49
- await this.queue.run(() => this.build());
47
+ await this.queue.add(() => this.build());
50
48
  }
51
49
  if (event === "add" || event === "change") {
52
50
  this.files[path] = null;
53
- await this.queue.run(() => this.build());
51
+ await this.queue.add(() => this.build());
54
52
  }
55
53
  };
56
54
  onReady = async () => {
@@ -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}`),
@@ -177,7 +175,7 @@ var Paralayer = class extends Unit {
177
175
  const LayerName = layer.split(".").map(this.capitalize).join("");
178
176
  if (style === "camel") return this.decapitalize(LayerName);
179
177
  if (style === "Pascal") return LayerName;
180
- throw this.never;
178
+ throw this.never();
181
179
  }
182
180
  capitalize(string) {
183
181
  return string.charAt(0).toUpperCase() + string.slice(1);
@@ -195,9 +193,8 @@ var Paralayer = class extends Unit {
195
193
  }
196
194
  };
197
195
  async function paralayer(options) {
198
- const pl = new Paralayer(options);
199
- await pl.start();
200
- return await pl.readSetupJs();
196
+ const setupLayersJs = await new Paralayer(options).start();
197
+ return setupLayersJs;
201
198
  }
202
199
  var paralayer_default = paralayer;
203
200
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paralayer",
3
- "version": "1.9.0",
3
+ "version": "1.11.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,8 +33,8 @@
30
33
  "dist"
31
34
  ],
32
35
  "dependencies": {
33
- "@eposlabs/utils": "^1.9.0",
34
- "chokidar": "^4.0.3",
36
+ "chokidar": "^5.0.0",
37
+ "dropcap": "^1.0.0",
35
38
  "minimist": "^1.2.8"
36
39
  },
37
40
  "devDependencies": {
package/src/paralayer.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { Queue, Unit, safe } from '@eposlabs/utils'
2
- import type { FSWatcher } from 'chokidar'
3
- import { watch } from 'chokidar'
1
+ import { watch, type FSWatcher } from 'chokidar'
2
+ import { Queue, Unit, safe } from 'dropcap/utils'
4
3
  import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'
5
4
  import { basename, extname, join, relative } from 'node:path'
6
5
 
@@ -19,7 +18,7 @@ export type Options = {
19
18
  globalize?: boolean
20
19
  /** If provided, other layers will extend this layer. */
21
20
  globalLayerName?: string | null
22
- /** If a file name does not have layer tags, default layer name will be used. */
21
+ /** If a file name does not have any layer tags, default layer name will be used. */
23
22
  defaultLayerName?: string | null
24
23
  }
25
24
 
@@ -50,11 +49,10 @@ export class Paralayer extends Unit {
50
49
  this.watcher.on('ready', this.onReady)
51
50
 
52
51
  await this.ready$.promise
53
- await this.queue.run(() => this.build())
52
+ await this.queue.add(() => this.build())
54
53
  if (!this.options.watch) await this.watcher.close()
55
- }
56
54
 
57
- async readSetupJs() {
55
+ // Return content of setup.js
58
56
  const setupJsPath = join(this.options.output, 'setup.js')
59
57
  return await readFile(setupJsPath, 'utf-8')
60
58
  }
@@ -83,13 +81,13 @@ export class Paralayer extends Unit {
83
81
  // File removed? -> Remove and rebuild
84
82
  if (event === 'unlink') {
85
83
  delete this.files[path]
86
- await this.queue.run(() => this.build())
84
+ await this.queue.add(() => this.build())
87
85
  }
88
86
 
89
87
  // File added/changed? -> Reset its content and rebuild
90
88
  if (event === 'add' || event === 'change') {
91
89
  this.files[path] = null
92
- await this.queue.run(() => this.build())
90
+ await this.queue.add(() => this.build())
93
91
  }
94
92
  }
95
93
 
@@ -201,7 +199,7 @@ export class Paralayer extends Unit {
201
199
 
202
200
  const globals = [
203
201
  `declare global {`,
204
- ` var ${layerName}: ${LayerName}`,
202
+ ` const ${layerName}: ${LayerName}`,
205
203
  ``,
206
204
  ` interface ${LayerName} ${extendPascal}{`,
207
205
  ...allNames.map(name => ` ${name}: typeof ${name}`),
@@ -262,7 +260,7 @@ export class Paralayer extends Unit {
262
260
  const LayerName = layer.split('.').map(this.capitalize).join('')
263
261
  if (style === 'camel') return this.decapitalize(LayerName)
264
262
  if (style === 'Pascal') return LayerName
265
- throw this.never
263
+ throw this.never()
266
264
  }
267
265
 
268
266
  private capitalize(string: string) {
@@ -285,9 +283,8 @@ export class Paralayer extends Unit {
285
283
  }
286
284
 
287
285
  export async function paralayer(options: Options) {
288
- const pl = new Paralayer(options)
289
- await pl.start()
290
- return await pl.readSetupJs()
286
+ const setupLayersJs = await new Paralayer(options).start()
287
+ return setupLayersJs
291
288
  }
292
289
 
293
290
  export default paralayer