lvyjs 0.2.16 → 0.2.18

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # LVY
1
+ # LYVJS
2
2
 
3
- 一款为 node 构建的开发工具
3
+ 一款为 NodeJS 构建的开发工具
4
4
 
5
- https://github.com/lemonade-lab/lvyjs
5
+ https://lvyjs.dev
package/bin/index.js CHANGED
@@ -3,23 +3,15 @@
3
3
  import { fork } from 'child_process'
4
4
  import { join, dirname, relative } from 'path'
5
5
  import { fileURLToPath } from 'node:url'
6
- import { existsSync } from 'fs'
6
+ import { createRequire } from 'node:module'
7
7
  const args = [...process.argv.slice(2)]
8
8
  const currentFilePath = fileURLToPath(import.meta.url)
9
9
  const currentDirPath = dirname(currentFilePath)
10
10
  const pkgFilr = join(currentDirPath, '../package.json')
11
11
  const jsFile = join(currentDirPath, '../lib/index.js')
12
12
  const jsdir = relative(process.cwd(), jsFile)
13
- let tsxDir = join(currentDirPath, '../../tsx/dist/cli.mjs')
14
- if (!existsSync(tsxDir)) {
15
- tsxDir = join(currentDirPath, '../node_modules/tsx/dist/cli.mjs')
16
- }
17
- if (!existsSync(tsxDir)) {
18
- tsxDir = join(process.cwd(), 'node_modules/tsx/dist/cli.mjs')
19
- }
20
- if (!existsSync(tsxDir)) {
21
- new Error('tsx not found')
22
- }
13
+ const require = createRequire(import.meta.url)
14
+ const tsxDir = require.resolve('tsx/cli')
23
15
  if (args.includes('build')) {
24
16
  const argsx = args.filter(arg => arg !== 'build')
25
17
  const msg = fork(tsxDir, [jsdir, '--lvy-build', ...argsx], {
package/lib/content.js CHANGED
@@ -7,9 +7,10 @@ import { convertPath } from './config.js';
7
7
  * @param {string} relativePath 相对路径
8
8
  */
9
9
  const generateModuleContent = (relativePath) => {
10
+ const baseURL = decodeURIComponent(relativePath);
10
11
  const contents = [
11
12
  `const reg = ['win32'].includes(process.platform) ? /^file:\\/\\/\\// : /^file:\\/\\// ;`,
12
- `const fileUrl = import.meta.resolve('${convertPath(relativePath)}').replace(reg, '');`,
13
+ `const fileUrl = import.meta.resolve('${convertPath(baseURL)}').replace(reg, '');`,
13
14
  'export default fileUrl;'
14
15
  ].join('\n');
15
16
  return contents;
@@ -27,20 +28,21 @@ const chache = {};
27
28
  * @param fileUrl
28
29
  * @returns
29
30
  */
30
- const generateCSSModuleContent = (pathURL) => {
31
- const fileName = getRandomName(pathURL);
32
- const outputFileURL = convertPath(join(process.cwd(), 'node_modules', 'lvyjs', 'assets', `${fileName}.css`));
33
- if (!chache[pathURL]) {
31
+ const generateCSSModuleContent = (relativePath) => {
32
+ const inputURL = decodeURIComponent(relativePath);
33
+ const fileName = getRandomName(inputURL);
34
+ const outputURL = convertPath(join(process.cwd(), 'node_modules', 'lvyjs', 'assets', `${fileName}.css`));
35
+ if (!chache[inputURL]) {
34
36
  global.lvyWorkerProt.postMessage({
35
37
  type: 'CSS_MODULE_GENERATED',
36
38
  payload: {
37
- from: pathURL,
38
- to: outputFileURL
39
+ from: inputURL,
40
+ to: outputURL
39
41
  }
40
42
  });
41
- chache[pathURL] = true;
43
+ chache[inputURL] = true;
42
44
  }
43
- return `export default "${outputFileURL}";`;
45
+ return `export default "${outputURL}";`;
44
46
  };
45
47
 
46
48
  export { generateCSSModuleContent, generateModuleContent };
package/lib/loader.d.ts CHANGED
@@ -4,6 +4,7 @@ declare global {
4
4
  var lvyWorkerProt: MessagePort;
5
5
  }
6
6
  /**
7
+ * 初始化时
7
8
  * @param param0
8
9
  */
9
10
  declare function initialize({ port, lvyConfig }: {
@@ -11,6 +12,7 @@ declare function initialize({ port, lvyConfig }: {
11
12
  lvyConfig: any;
12
13
  }): Promise<void>;
13
14
  /**
15
+ * 启动时
14
16
  * @param specifier
15
17
  * @param context
16
18
  * @param nextResolve
@@ -18,6 +20,7 @@ declare function initialize({ port, lvyConfig }: {
18
20
  */
19
21
  declare function resolve(specifier: any, context: any, nextResolve: any): Promise<any>;
20
22
  /**
23
+ * 加载脚本时
21
24
  * @param url
22
25
  * @param context
23
26
  * @param defaultLoad
package/lib/loader.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { generateModuleContent, generateCSSModuleContent } from './content.js';
2
2
  import { isWin32, convertPath } from './config.js';
3
3
 
4
+ // 用来消去 路径中的 file:///
4
5
  const reg = isWin32() ? /^file:\/\/\// : /^file:\/\//;
5
6
  const baseURL = isWin32() ? 'file:///' : 'file://';
6
7
  const nodeReg = /(node_modules|node_|node:)/;
7
8
  /**
9
+ * 初始化时
8
10
  * @param param0
9
11
  */
10
12
  async function initialize({ port, lvyConfig }) {
@@ -12,6 +14,7 @@ async function initialize({ port, lvyConfig }) {
12
14
  global.lvyWorkerProt = port;
13
15
  }
14
16
  /**
17
+ * 启动时
15
18
  * @param specifier
16
19
  * @param context
17
20
  * @param nextResolve
@@ -35,6 +38,7 @@ async function resolve(specifier, context, nextResolve) {
35
38
  return nextResolve(specifier, context);
36
39
  }
37
40
  /**
41
+ * 加载脚本时
38
42
  * @param url
39
43
  * @param context
40
44
  * @param defaultLoad
@@ -52,7 +56,9 @@ const load = (url, context, nextLoad) => {
52
56
  }
53
57
  // 匹配静态资源
54
58
  if (global.lvyConfig.assets?.filter && global.lvyConfig.assets?.filter.test(baseURL)) {
55
- const code = generateModuleContent(baseURL.replace(reg, ''));
59
+ // 消除 file:///
60
+ const url = baseURL.replace(reg, '');
61
+ const code = generateModuleContent(url);
56
62
  return nextLoad(baseURL, {
57
63
  format: 'module',
58
64
  source: code
@@ -62,7 +68,9 @@ const load = (url, context, nextLoad) => {
62
68
  global.lvyConfig.styles = {};
63
69
  }
64
70
  if (global.lvyConfig.styles?.filter && global.lvyConfig.styles?.filter.test(baseURL)) {
65
- const code = generateCSSModuleContent(baseURL.replace(reg, ''));
71
+ // 消除 file:///
72
+ const url = baseURL.replace(reg, '');
73
+ const code = generateCSSModuleContent(url);
66
74
  return nextLoad(baseURL, {
67
75
  format: 'module',
68
76
  source: code
package/lib/main.js CHANGED
@@ -12,7 +12,9 @@ port1.on('message', msg => {
12
12
  if (msg.type == 'CSS_MODULE_GENERATED') {
13
13
  const { from, to } = msg.payload;
14
14
  if (!cache[from]) {
15
- postCSS(from, to);
15
+ const formPath = decodeURIComponent(from);
16
+ postCSS(formPath, to);
17
+ // postCSS(from, to)
16
18
  cache[from] = true;
17
19
  }
18
20
  }
@@ -0,0 +1,10 @@
1
+ const createFuncCode = (code) => {
2
+ return `
3
+ (() => {
4
+ ${code}
5
+ return css;
6
+ })()
7
+ `;
8
+ };
9
+
10
+ export { createFuncCode };
@@ -1,6 +1,7 @@
1
1
  import { createFilter } from '@rollup/pluginutils';
2
2
  import { basename, resolve, dirname } from 'node:path';
3
3
  import { stylesRegExp } from '../../config.js';
4
+ import { createFuncCode } from './funcCode.js';
4
5
 
5
6
  /**
6
7
  *
@@ -25,16 +26,11 @@ const rollupStylesCSSImport = (options) => {
25
26
  if (!filter(id))
26
27
  return null;
27
28
  // 删除 export default css
28
- const codex = code.replace(/(export|default css)/g, '');
29
+ const curCode = code.replace(/(export|default css)/g, '');
29
30
  // 使用 eval 执行代码并获取默认导出的值
30
- const evalCode = `
31
- (() => {
32
- ${codex}
33
- return css;
34
- })()
35
- `;
31
+ const funcCode = createFuncCode(curCode);
36
32
  // 得到css变量的值
37
- const csscode = eval(evalCode);
33
+ const csscode = eval(funcCode);
38
34
  // 确保最后生产的css文件
39
35
  const refeId = this.emitFile({
40
36
  // 属于静态资源
package/lib/store.d.ts CHANGED
@@ -85,4 +85,5 @@ declare const getOptions: () => Options;
85
85
  */
86
86
  declare const defineConfig: (optoins?: Options) => Options | undefined;
87
87
 
88
- export { type Options, type PluginsCallBack, type PluginsOptions, type PluginsValue, defineConfig, getOptions, initConfig };
88
+ export { defineConfig, getOptions, initConfig };
89
+ export type { Options, PluginsCallBack, PluginsOptions, PluginsValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lvyjs",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "description": "tsx compile script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",