lvyjs 0.2.14 → 0.2.15

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/lib/store.js CHANGED
@@ -1,40 +1,41 @@
1
- import { existsSync } from 'fs'
2
- import { join } from 'path'
1
+ import { existsSync } from 'fs';
2
+ import { join } from 'path';
3
3
 
4
4
  /**
5
5
  *
6
6
  */
7
7
  const initConfig = async () => {
8
- if (!global.lvyConfig) global.lvyConfig = {}
9
- const files = [
10
- 'lvy.config.ts',
11
- 'lvy.config.js',
12
- 'lvy.config.mjs',
13
- 'lvy.config.cjs',
14
- 'lvy.config.tsx'
15
- ]
16
- let configDir = ''
17
- for (const file of files) {
18
- if (existsSync(file)) {
19
- configDir = file
20
- break
8
+ if (!global.lvyConfig)
9
+ global.lvyConfig = {};
10
+ const files = [
11
+ 'lvy.config.ts',
12
+ 'lvy.config.js',
13
+ 'lvy.config.mjs',
14
+ 'lvy.config.cjs',
15
+ 'lvy.config.tsx'
16
+ ];
17
+ let configDir = '';
18
+ for (const file of files) {
19
+ if (existsSync(file)) {
20
+ configDir = file;
21
+ break;
22
+ }
21
23
  }
22
- }
23
- if (configDir !== '') {
24
- const v = await import(`file://${join(process.cwd(), configDir)}`)
25
- if (v?.default) {
26
- global.lvyConfig = v.default
24
+ if (configDir !== '') {
25
+ const v = await import(`file://${join(process.cwd(), configDir)}`);
26
+ if (v?.default) {
27
+ global.lvyConfig = v.default;
28
+ }
27
29
  }
28
- }
29
- }
30
+ };
30
31
  /**
31
32
  * @returns
32
33
  */
33
- const getOptions = () => global.lvyConfig
34
+ const getOptions = () => global.lvyConfig;
34
35
  /**
35
36
  * @param param0
36
37
  * @returns
37
38
  */
38
- const defineConfig = optoins => optoins
39
+ const defineConfig = (optoins) => optoins;
39
40
 
40
- export { defineConfig, getOptions, initConfig }
41
+ export { defineConfig, getOptions, initConfig };
package/lib/typing.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  interface Alias {
2
- find: string
3
- replacement: string
2
+ find: string;
3
+ replacement: string;
4
4
  }
5
5
 
6
- export type { Alias }
6
+ export type { Alias };
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "lvyjs",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "tsx compile script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "lib/index.js",
9
+ "scripts": {
10
+ "build": "node bundle.js"
11
+ },
9
12
  "dependencies": {
10
13
  "@rollup/plugin-alias": "^5.1.0",
11
14
  "@rollup/plugin-commonjs": "^28.0.0",
@@ -42,6 +45,10 @@
42
45
  "./tsconfig.json": {
43
46
  "import": "./tsconfig.json",
44
47
  "types": "./tsconfig.json"
48
+ },
49
+ "./tsconfig": {
50
+ "import": "./tsconfig.json",
51
+ "types": "./tsconfig.json"
45
52
  }
46
53
  },
47
54
  "bin": {
@@ -50,15 +57,17 @@
50
57
  "keywords": [
51
58
  "ts",
52
59
  "tsx",
53
- "react"
60
+ "react",
61
+ "rullup",
62
+ "esbuild"
54
63
  ],
55
64
  "publishConfig": {
56
65
  "registry": "https://registry.npmjs.org",
57
66
  "access": "public"
58
67
  },
59
- "bugs": "https://github.com/lvyjs/core/issues",
68
+ "bugs": "https://github.com/lemonade-lab/lvyjs/issues",
60
69
  "repository": {
61
70
  "type": "git",
62
- "url": "https://github.com/lvyjs/core.git"
71
+ "url": "https://github.com/lemonade-lab/lvyjs.git"
63
72
  }
64
73
  }
package/lib/content.js DELETED
@@ -1,48 +0,0 @@
1
- import { join } from 'path'
2
- import crypto from 'node:crypto'
3
- import { convertPath } from './config.js'
4
-
5
- /**
6
- * 生成模块内容
7
- * @param {string} relativePath 相对路径
8
- */
9
- const generateModuleContent = relativePath => {
10
- const contents = [
11
- `const reg = ['win32'].includes(process.platform) ? /^file:\\/\\/\\// : /^file:\\/\\// ;`,
12
- `const fileUrl = import.meta.resolve('${convertPath(relativePath)}').replace(reg, '');`,
13
- 'export default fileUrl;'
14
- ].join('\n')
15
- return contents
16
- }
17
- const getRandomName = str => {
18
- // 使用 MD5 算法创建哈希对象
19
- const hash = crypto.createHash('md5')
20
- // 更新哈希对象内容
21
- hash.update(str)
22
- return hash.digest('hex')
23
- }
24
- const chache = {}
25
- /**
26
- *
27
- * @param fileUrl
28
- * @returns
29
- */
30
- const generateCSSModuleContent = pathURL => {
31
- const fileName = getRandomName(pathURL)
32
- const outputFileURL = convertPath(
33
- join(process.cwd(), 'node_modules', 'lvyjs', 'assets', `${fileName}.css`)
34
- )
35
- if (!chache[pathURL]) {
36
- global.lvyWorkerProt.postMessage({
37
- type: 'CSS_MODULE_GENERATED',
38
- payload: {
39
- from: pathURL,
40
- to: outputFileURL
41
- }
42
- })
43
- chache[pathURL] = true
44
- }
45
- return `export default "${outputFileURL}";`
46
- }
47
-
48
- export { generateCSSModuleContent, generateModuleContent }
package/lib/loader.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { MessagePort } from 'worker_threads'
2
-
3
- declare global {
4
- var lvyWorkerProt: MessagePort
5
- }
6
- /**
7
- * @param param0
8
- */
9
- declare function initialize({ port, lvyConfig }: { port: any; lvyConfig: any }): Promise<void>
10
- /**
11
- * @param specifier
12
- * @param context
13
- * @param nextResolve
14
- * @returns
15
- */
16
- declare function resolve(specifier: any, context: any, nextResolve: any): Promise<any>
17
- /**
18
- * @param url
19
- * @param context
20
- * @param defaultLoad
21
- * @returns
22
- */
23
- declare const load: (url: any, context: any, nextLoad: any) => any
24
-
25
- export { initialize, load, resolve }
package/lib/loader.js DELETED
@@ -1,74 +0,0 @@
1
- import { generateModuleContent, generateCSSModuleContent } from './content.js'
2
- import { isWin32, convertPath } from './config.js'
3
-
4
- const reg = isWin32() ? /^file:\/\/\// : /^file:\/\//
5
- const baseURL = isWin32() ? 'file:///' : 'file://'
6
- const nodeReg = /(node_modules|node_|node:)/
7
- /**
8
- * @param param0
9
- */
10
- async function initialize({ port, lvyConfig }) {
11
- global.lvyConfig = lvyConfig
12
- global.lvyWorkerProt = port
13
- }
14
- /**
15
- * @param specifier
16
- * @param context
17
- * @param nextResolve
18
- * @returns
19
- */
20
- async function resolve(specifier, context, nextResolve) {
21
- if (!global.lvyConfig?.alias) {
22
- global.lvyConfig.alias = {}
23
- }
24
- if (global.lvyConfig.alias?.entries) {
25
- for (const { find, replacement } of global.lvyConfig.alias?.entries) {
26
- if (specifier.startsWith(find)) {
27
- const parentURL = `${baseURL}${convertPath(specifier.replace(find, replacement))}`
28
- return nextResolve(specifier, {
29
- ...context,
30
- parentURL: parentURL
31
- })
32
- }
33
- }
34
- }
35
- return nextResolve(specifier, context)
36
- }
37
- /**
38
- * @param url
39
- * @param context
40
- * @param defaultLoad
41
- * @returns
42
- */
43
- const load = (url, context, nextLoad) => {
44
- if (nodeReg.test(url)) {
45
- return nextLoad(url, context)
46
- }
47
- const urls = url.split('?')
48
- const baseURL = urls[0]
49
- // 得到静态资源。转为普通的文件引用。
50
- if (!global.lvyConfig.assets) {
51
- global.lvyConfig.assets = {}
52
- }
53
- // 匹配静态资源
54
- if (global.lvyConfig.assets?.filter && global.lvyConfig.assets?.filter.test(baseURL)) {
55
- const code = generateModuleContent(baseURL.replace(reg, ''))
56
- return nextLoad(baseURL, {
57
- format: 'module',
58
- source: code
59
- })
60
- }
61
- if (!global.lvyConfig.styles) {
62
- global.lvyConfig.styles = {}
63
- }
64
- if (global.lvyConfig.styles?.filter && global.lvyConfig.styles?.filter.test(baseURL)) {
65
- const code = generateCSSModuleContent(baseURL.replace(reg, ''))
66
- return nextLoad(baseURL, {
67
- format: 'module',
68
- source: code
69
- })
70
- }
71
- return nextLoad(url, context)
72
- }
73
-
74
- export { initialize, load, resolve }