lvyjs 0.2.11 → 0.2.13

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