paralayer 1.0.4 → 1.0.6

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
@@ -1,9 +1,9 @@
1
1
  import minimist from 'minimist';
2
- import { Paralayer } from './paralayer.js';
2
+ import { paralayer } from './index.js';
3
3
  const argv = minimist(process.argv.slice(2), {
4
4
  string: ['default'],
5
5
  boolean: ['watch', 'globalize'],
6
- default: { default: null, watch: false, globalize: false },
6
+ default: { watch: false, default: null, globalize: false },
7
7
  });
8
8
  const paths = argv._;
9
9
  const input = paths.slice(0, -1);
@@ -16,12 +16,10 @@ if (!output) {
16
16
  console.error('[paralayer] Output directory is not provided');
17
17
  process.exit(1);
18
18
  }
19
- const paralayer = new Paralayer({
19
+ await paralayer({
20
20
  input: input,
21
21
  output: output,
22
- globalize: argv.globalize,
23
- default: argv.default,
24
- });
25
- await paralayer.start({
26
22
  watch: argv.watch,
23
+ default: argv.default,
24
+ globalize: argv.globalize,
27
25
  });
package/dist/index.d.ts CHANGED
@@ -1 +1,3 @@
1
- export { Paralayer, type Options } from './paralayer.js';
1
+ import { type Options } from './paralayer.js';
2
+ export declare function paralayer(options: Options): Promise<string>;
3
+ export default paralayer;
package/dist/index.js CHANGED
@@ -1 +1,7 @@
1
- export { Paralayer } from './paralayer.js';
1
+ import { Paralayer } from './paralayer.js';
2
+ export async function paralayer(options) {
3
+ const pl = new Paralayer(options);
4
+ await pl.start();
5
+ return await pl.readSetupJs();
6
+ }
7
+ export default paralayer;
@@ -1,5 +1,4 @@
1
1
  import * as $utils from '@eposlabs/utils';
2
- import type { Plugin } from 'vite';
3
2
  export type DirPath = string;
4
3
  export type File = {
5
4
  content: string;
@@ -8,6 +7,7 @@ export type File = {
8
7
  export type Options = {
9
8
  input: DirPath | DirPath[];
10
9
  output: DirPath;
10
+ watch?: boolean;
11
11
  /** Default layer name. If a file name does not have layer tags, default name will be used. */
12
12
  default?: string | null;
13
13
  /** Whether the layer variables should be exposed globally. */
@@ -23,14 +23,9 @@ export declare class Paralayer extends $utils.Unit {
23
23
  private extensions;
24
24
  private previousLayers;
25
25
  private watcher;
26
- private viteConfig;
27
26
  constructor(options: Options);
28
- get vite(): Plugin;
29
- start: ({ watch }?: {
30
- watch?: boolean | undefined;
31
- }) => Promise<void>;
32
- private onConfigResolved;
33
- private onBuildStart;
27
+ start: () => Promise<void>;
28
+ readSetupJs(): Promise<string>;
34
29
  private onAll;
35
30
  private onReady;
36
31
  private build;
package/dist/paralayer.js CHANGED
@@ -1,7 +1,7 @@
1
+ import * as $utils from '@eposlabs/utils';
1
2
  import * as $chokidar from 'chokidar';
2
3
  import * as $fs from 'node:fs/promises';
3
4
  import * as $path from 'node:path';
4
- import * as $utils from '@eposlabs/utils';
5
5
  export class Paralayer extends $utils.Unit {
6
6
  files = {};
7
7
  options;
@@ -12,20 +12,11 @@ export class Paralayer extends $utils.Unit {
12
12
  extensions = new Set(['.ts', '.tsx', '.js', '.jsx']);
13
13
  previousLayers = [];
14
14
  watcher = null;
15
- viteConfig = null;
16
15
  constructor(options) {
17
16
  super();
18
17
  this.options = options;
19
18
  }
20
- get vite() {
21
- return {
22
- name: 'paralayer',
23
- enforce: 'pre',
24
- configResolved: this.onConfigResolved,
25
- buildStart: this.onBuildStart,
26
- };
27
- }
28
- start = async ({ watch = false } = {}) => {
19
+ start = async () => {
29
20
  if (this.started)
30
21
  return;
31
22
  this.started = true;
@@ -35,20 +26,13 @@ export class Paralayer extends $utils.Unit {
35
26
  this.watcher.on('ready', this.onReady);
36
27
  await this.ready$.promise;
37
28
  await this.queue.run(() => this.build());
38
- if (!watch)
29
+ if (!this.options.watch)
39
30
  await this.watcher.close();
40
31
  };
41
- // ---------------------------------------------------------------------------
42
- // VITE HOOKS
43
- // ---------------------------------------------------------------------------
44
- onConfigResolved = (config) => {
45
- this.viteConfig = config;
46
- };
47
- onBuildStart = async () => {
48
- if (!this.viteConfig)
49
- throw this.never;
50
- await this.start({ watch: !!this.viteConfig.build.watch });
51
- };
32
+ async readSetupJs() {
33
+ const setupJsPath = $path.join(this.options.output, 'setup.js');
34
+ return await $fs.readFile(setupJsPath, 'utf-8');
35
+ }
52
36
  // ---------------------------------------------------------------------------
53
37
  // HANDLERS
54
38
  // ---------------------------------------------------------------------------
@@ -140,6 +124,8 @@ export class Paralayer extends $utils.Unit {
140
124
  // HELPERS
141
125
  // ---------------------------------------------------------------------------
142
126
  extractExportedClassNames(content) {
127
+ if (content.includes('paralayer-ignore'))
128
+ return [];
143
129
  return content
144
130
  .split('export class ')
145
131
  .slice(1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paralayer",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "imkost",
@@ -13,9 +13,7 @@
13
13
  "dev": "rm -rf dist && tsc --watch",
14
14
  "build": "rm -rf dist && tsc",
15
15
  "lint": "tsc --noEmit",
16
- "release": "npm version patch && npm run release:raw",
17
- "release:raw": "npm run build && npm publish",
18
- "release:minor": "npm version minor && npm run release:raw"
16
+ "release": "sh -c 'npm version ${1:-patch} && npm run build && npm publish' --"
19
17
  },
20
18
  "bin": {
21
19
  "paralayer": "bin.js"
@@ -24,10 +22,6 @@
24
22
  ".": {
25
23
  "default": "./dist/index.js",
26
24
  "types": "./dist/index.d.ts"
27
- },
28
- "./vite": {
29
- "default": "./dist/vite.js",
30
- "types": "./dist/vite.d.ts"
31
25
  }
32
26
  },
33
27
  "files": [
@@ -35,7 +29,7 @@
35
29
  "bin.js"
36
30
  ],
37
31
  "dependencies": {
38
- "chalk": "^5.6.0",
32
+ "@eposlabs/utils": "^1.0.0",
39
33
  "chokidar": "^4.0.3",
40
34
  "minimist": "^1.2.8"
41
35
  },
package/dist/vite.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { type Options } from './paralayer.js';
2
- export default function paralayer(options: Options): import("vite").Plugin<any>;
package/dist/vite.js DELETED
@@ -1,4 +0,0 @@
1
- import { Paralayer } from './paralayer.js';
2
- export default function paralayer(options) {
3
- return new Paralayer(options).vite;
4
- }