lvyjs 0.2.17 → 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.
@@ -1,54 +1,52 @@
1
- import { createFilter } from '@rollup/pluginutils'
2
- import { basename, resolve, dirname } from 'node:path'
3
- import { stylesRegExp } from '../../config.js'
1
+ import { createFilter } from '@rollup/pluginutils';
2
+ import { basename, resolve, dirname } from 'node:path';
3
+ import { stylesRegExp } from '../../config.js';
4
+ import { createFuncCode } from './funcCode.js';
4
5
 
5
6
  /**
6
7
  *
7
8
  * @returns
8
9
  */
9
- const rollupStylesCSSImport = options => {
10
- const include = options?.filter ?? stylesRegExp
11
- const filter = createFilter(include, null)
12
- return {
13
- name: 'c-css',
14
- resolveId(source, importer) {
15
- if (filter(source) && importer) {
16
- return resolve(dirname(importer), source)
17
- }
18
- },
19
- load(id) {
20
- if (filter(id)) this.addWatchFile(resolve(id))
21
- return null
22
- },
23
- async transform(code, id) {
24
- if (!filter(id)) return null
25
- // 删除 export default css
26
- const codex = code.replace(/(export|default css)/g, '')
27
- // 使用 eval 执行代码并获取默认导出的值
28
- const evalCode = `
29
- (() => {
30
- ${codex}
31
- return css;
32
- })()
33
- `
34
- // 得到css变量的值
35
- const csscode = eval(evalCode)
36
- // 确保最后生产的css文件
37
- const refeId = this.emitFile({
38
- // 属于静态资源
39
- type: 'asset',
40
- name: basename(`${id}.css`),
41
- // 内容
42
- source: csscode
43
- })
44
- const contents = [
45
- `const reg = ['win32'].includes(process.platform) ? /^file:\\/\\/\\// : /^file:\\/\\// ;`,
46
- `const fileUrl = import.meta.ROLLUP_FILE_URL_${refeId}.replace(reg, '');`,
47
- 'export default fileUrl;'
48
- ].join('\n')
49
- return contents
50
- }
51
- }
52
- }
10
+ const rollupStylesCSSImport = (options) => {
11
+ const include = options?.filter ?? stylesRegExp;
12
+ const filter = createFilter(include, null);
13
+ return {
14
+ name: 'c-css',
15
+ resolveId(source, importer) {
16
+ if (filter(source) && importer) {
17
+ return resolve(dirname(importer), source);
18
+ }
19
+ },
20
+ load(id) {
21
+ if (filter(id))
22
+ this.addWatchFile(resolve(id));
23
+ return null;
24
+ },
25
+ async transform(code, id) {
26
+ if (!filter(id))
27
+ return null;
28
+ // 删除 export default css
29
+ const curCode = code.replace(/(export|default css)/g, '');
30
+ // 使用 eval 执行代码并获取默认导出的值
31
+ const funcCode = createFuncCode(curCode);
32
+ // 得到css变量的值
33
+ const csscode = eval(funcCode);
34
+ // 确保最后生产的css文件
35
+ const refeId = this.emitFile({
36
+ // 属于静态资源
37
+ type: 'asset',
38
+ name: basename(`${id}.css`),
39
+ // 内容
40
+ source: csscode
41
+ });
42
+ const contents = [
43
+ `const reg = ['win32'].includes(process.platform) ? /^file:\\/\\/\\// : /^file:\\/\\// ;`,
44
+ `const fileUrl = import.meta.ROLLUP_FILE_URL_${refeId}.replace(reg, '');`,
45
+ 'export default fileUrl;'
46
+ ].join('\n');
47
+ return contents;
48
+ }
49
+ };
50
+ };
53
51
 
54
- export { rollupStylesCSSImport }
52
+ export { rollupStylesCSSImport };
@@ -1,36 +1,36 @@
1
- import { basename, resolve, dirname } from 'path'
2
- import { readFileSync } from 'fs'
3
- import { assetsRegExp } from '../../config.js'
1
+ import { basename, resolve, dirname } from 'path';
2
+ import { readFileSync } from 'fs';
3
+ import { assetsRegExp } from '../../config.js';
4
4
 
5
5
  /**
6
6
  * @param {Object} options
7
7
  * @returns {Object}
8
8
  */
9
- const rollupAssets = options => {
10
- const { filter = assetsRegExp } = options ?? {}
11
- return {
12
- name: 'rollup-node-files',
13
- resolveId(source, importer) {
14
- if (filter.test(source) && importer) {
15
- return resolve(dirname(importer), source)
16
- }
17
- },
18
- load(id) {
19
- if (filter.test(id)) {
20
- const referenceId = this.emitFile({
21
- type: 'asset',
22
- name: basename(id),
23
- source: readFileSync(id)
24
- })
25
- const contents = [
26
- `const reg = ['win32'].includes(process.platform) ? /^file:\\/\\/\\// : /^file:\\/\\// ;`,
27
- `const fileUrl = import.meta.ROLLUP_FILE_URL_${referenceId}.replace(reg, '');`,
28
- 'export default fileUrl;'
29
- ].join('\n')
30
- return contents
31
- }
32
- }
33
- }
34
- }
9
+ const rollupAssets = (options) => {
10
+ const { filter = assetsRegExp } = options ?? {};
11
+ return {
12
+ name: 'rollup-node-files',
13
+ resolveId(source, importer) {
14
+ if (filter.test(source) && importer) {
15
+ return resolve(dirname(importer), source);
16
+ }
17
+ },
18
+ load(id) {
19
+ if (filter.test(id)) {
20
+ const referenceId = this.emitFile({
21
+ type: 'asset',
22
+ name: basename(id),
23
+ source: readFileSync(id)
24
+ });
25
+ const contents = [
26
+ `const reg = ['win32'].includes(process.platform) ? /^file:\\/\\/\\// : /^file:\\/\\// ;`,
27
+ `const fileUrl = import.meta.ROLLUP_FILE_URL_${referenceId}.replace(reg, '');`,
28
+ 'export default fileUrl;'
29
+ ].join('\n');
30
+ return contents;
31
+ }
32
+ }
33
+ };
34
+ };
35
35
 
36
- export { rollupAssets }
36
+ export { rollupAssets };
@@ -1,27 +1,26 @@
1
- import { join } from 'path'
2
- import { readdirSync } from 'fs'
1
+ import { join } from 'path';
2
+ import { readdirSync } from 'fs';
3
3
 
4
4
  /**
5
5
  * 获取指定目录下的所有 ts、js、jsx、tsx 文件
6
6
  * @param dir 目录路径
7
7
  * @returns 文件路径数组
8
8
  */
9
- const getScriptFiles = dir => {
10
- const results = []
11
- const list = readdirSync(dir, { withFileTypes: true })
12
- list.forEach(item => {
13
- const fullPath = join(dir, item.name)
14
- if (item.isDirectory()) {
15
- results.push(...getScriptFiles(fullPath))
16
- } else if (
17
- item.isFile() &&
18
- /\.(ts|js|jsx|tsx)$/.test(item.name) &&
19
- !item.name.endsWith('.d.ts')
20
- ) {
21
- results.push(fullPath)
22
- }
23
- })
24
- return results
25
- }
9
+ const getScriptFiles = (dir) => {
10
+ const results = [];
11
+ const list = readdirSync(dir, { withFileTypes: true });
12
+ list.forEach(item => {
13
+ const fullPath = join(dir, item.name);
14
+ if (item.isDirectory()) {
15
+ results.push(...getScriptFiles(fullPath));
16
+ }
17
+ else if (item.isFile() &&
18
+ /\.(ts|js|jsx|tsx)$/.test(item.name) &&
19
+ !item.name.endsWith('.d.ts')) {
20
+ results.push(fullPath);
21
+ }
22
+ });
23
+ return results;
24
+ };
26
25
 
27
- export { getScriptFiles }
26
+ export { getScriptFiles };
package/lib/store.d.ts CHANGED
@@ -1,106 +1,89 @@
1
- import { RollupCommonJSOptions } from '@rollup/plugin-commonjs'
2
- import { RollupTypescriptOptions } from '@rollup/plugin-typescript'
3
- import { RollupOptions, OutputOptions } from 'rollup'
4
- import { Alias } from './typing.js'
1
+ import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';
2
+ import { RollupTypescriptOptions } from '@rollup/plugin-typescript';
3
+ import { RollupOptions, OutputOptions } from 'rollup';
4
+ import { Alias } from './typing.js';
5
5
 
6
- type PluginsValue = (options: Options) => void
7
- type PluginsCallBack =
8
- | PluginsValue
9
- | {
10
- load?: PluginsValue
11
- build?: PluginsValue
12
- }
13
- type PluginsOptions = (options: Options) => PluginsCallBack | void
6
+ type PluginsValue = (options: Options) => void;
7
+ type PluginsCallBack = PluginsValue | {
8
+ load?: PluginsValue;
9
+ build?: PluginsValue;
10
+ };
11
+ type PluginsOptions = (options: Options) => PluginsCallBack | void;
14
12
  type Options = {
15
- /**
16
- * 配置调整机及其回调插件
17
- */
18
- plugins?: PluginsOptions[]
19
- /**
20
- * 别名
21
- */
22
- alias?:
23
- | {
13
+ /**
14
+ * 配置调整机及其回调插件
15
+ */
16
+ plugins?: PluginsOptions[];
17
+ /**
18
+ * 别名
19
+ */
20
+ alias?: {
24
21
  /**
25
22
  * 别名规则
26
23
  */
27
- entries?: Alias[]
28
- }
29
- | false
30
- /**
31
- * 静态资源识别
32
- */
33
- assets?:
34
- | {
24
+ entries?: Alias[];
25
+ } | false;
26
+ /**
27
+ * 静态资源识别
28
+ */
29
+ assets?: {
35
30
  /**
36
31
  * 过滤得到指定格式的文件识别之为静态资源
37
32
  */
38
- filter?: RegExp
39
- }
40
- | false
41
- styles?:
42
- | {
33
+ filter?: RegExp;
34
+ } | false;
35
+ styles?: {
43
36
  /**
44
37
  * 过滤得到指定格式的文件识别之为静态资源
45
38
  */
46
- filter?: RegExp
47
- }
48
- | false
49
- /**
50
- * 打包时配置
51
- */
52
- build?:
53
- | {
39
+ filter?: RegExp;
40
+ } | false;
41
+ /**
42
+ * 打包时配置
43
+ */
44
+ build?: {
54
45
  /**
55
46
  * cjs文件处理
56
47
  */
57
- commonjs?: RollupCommonJSOptions | false
48
+ commonjs?: RollupCommonJSOptions | false;
58
49
  /**
59
50
  * ts配置
60
51
  */
61
- typescript?: RollupTypescriptOptions | false
52
+ typescript?: RollupTypescriptOptions | false;
62
53
  /**
63
54
  *
64
55
  */
65
- RollupOptions?: RollupOptions
56
+ RollupOptions?: RollupOptions;
66
57
  /**
67
58
  *
68
59
  */
69
60
  OutputOptions?: OutputOptions & {
70
- /**
71
- * 默认 src
72
- */
73
- input?: string
74
- }
75
- }
76
- | false
77
- }
61
+ /**
62
+ * 默认 src
63
+ */
64
+ input?: string;
65
+ };
66
+ } | false;
67
+ };
78
68
  /**
79
69
  *
80
70
  */
81
71
  declare global {
82
- var lvyConfig: Options
72
+ var lvyConfig: Options;
83
73
  }
84
74
  /**
85
75
  *
86
76
  */
87
- declare const initConfig: () => Promise<void>
77
+ declare const initConfig: () => Promise<void>;
88
78
  /**
89
79
  * @returns
90
80
  */
91
- declare const getOptions: () => Options
81
+ declare const getOptions: () => Options;
92
82
  /**
93
83
  * @param param0
94
84
  * @returns
95
85
  */
96
- declare const defineConfig: (optoins?: Options) => Options | undefined
86
+ declare const defineConfig: (optoins?: Options) => Options | undefined;
97
87
 
98
- export {
99
- type Options,
100
- type PluginsCallBack,
101
- type PluginsOptions,
102
- type PluginsValue,
103
- defineConfig,
104
- getOptions,
105
- initConfig
106
- }
88
+ export { defineConfig, getOptions, initConfig };
89
+ export type { Options, PluginsCallBack, PluginsOptions, PluginsValue };
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,6 +1,6 @@
1
1
  {
2
2
  "name": "lvyjs",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "tsx compile script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",