@lls/vitescripts 1.0.0-b28ab2cba → 1.0.0-c94f7be52
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/package.json +7 -8
- package/src/llsSideRefreshMetaPlugin.mjs +25 -25
package/package.json
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lls/vitescripts",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-c94f7be52",
|
|
4
4
|
"description": "lls vite plugins",
|
|
5
5
|
"main": "src/index.mjs",
|
|
6
6
|
"files": [
|
|
7
7
|
"src/"
|
|
8
8
|
],
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"
|
|
10
|
+
"browserslist": "4.22.1",
|
|
11
11
|
"esbuild-plugin-lightningcss-modules": "0.1.1",
|
|
12
|
-
"
|
|
12
|
+
"lightningcss": "1.22.1"
|
|
13
13
|
},
|
|
14
14
|
"type": "module",
|
|
15
15
|
"author": "",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@lls/eslint-config-lls": "1.1.12",
|
|
19
18
|
"@lls/lls-kit": "23.0.0",
|
|
20
19
|
"nano-staged": "0.8.0",
|
|
21
|
-
"vitest": "0.
|
|
20
|
+
"vitest": "1.0.4"
|
|
22
21
|
},
|
|
23
22
|
"nano-staged": {
|
|
24
|
-
"*.{js,jsx,mjs,tsx,ts}": "CONF_ENV=test
|
|
23
|
+
"*.{js,jsx,mjs,tsx,ts}": "CONF_ENV=test pnpm vitest related --run"
|
|
25
24
|
},
|
|
26
25
|
"scripts": {
|
|
27
|
-
"test": "CONF_ENV=test
|
|
28
|
-
"precommit": "
|
|
26
|
+
"test": "CONF_ENV=test pnpm vitest run",
|
|
27
|
+
"precommit": "pnpm nano-staged"
|
|
29
28
|
}
|
|
30
29
|
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
3
|
|
|
4
|
+
const pwd = process.cwd()
|
|
5
|
+
|
|
4
6
|
// sideRefreshActiveModules is of the form ['viewer', 'superkit', ...] with 'viewer' if repo launched
|
|
5
7
|
// WITH_VIEWER=1 npm start
|
|
6
8
|
export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules) => {
|
|
7
9
|
const parentDir = path.basename(path.dirname(process.cwd()))
|
|
8
10
|
const sideRefreshThemes = {}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
code: '@lls/lls-code/lib/css-bare.mjs'
|
|
17
|
-
}
|
|
18
|
-
await Promise.all(sideRefreshActiveModules.map(sideRefreshName => {
|
|
19
|
-
if (!cssThemeMap[sideRefreshName]) {
|
|
20
|
-
throw new Error('invalid side refresh name' + sideRefreshName)
|
|
21
|
-
}
|
|
22
|
-
return import(cssThemeMap[sideRefreshName]).then(m => {
|
|
23
|
-
const mod = m.default || m
|
|
24
|
-
sideRefreshThemes[`${sideRefreshName}_dark`] = mod.themeIsDarkMode
|
|
25
|
-
sideRefreshThemes[`${sideRefreshName}_free`] = mod.themeIsFreeMode
|
|
26
|
-
sideRefreshThemes[`${sideRefreshName}_light`] = mod.themeIsNotDarkMode
|
|
27
|
-
})
|
|
28
|
-
}))
|
|
11
|
+
const cssThemeMap = {
|
|
12
|
+
viewer: path.join(pwd, '../viewer/src/utils/css-bare.mjs'),
|
|
13
|
+
// kit: no themes for kit
|
|
14
|
+
superkit: path.join(pwd, '../superkit/src/internals/utils/css-bare.mjs'),
|
|
15
|
+
core: path.join(pwd, '../core/src/utils/css-bare.mjs'),
|
|
16
|
+
audio: path.join(pwd, '../lls-audio/src/utils/css-bare.mjs'),
|
|
17
|
+
code: path.join(pwd, '../lls-code/src/utils/css-bare.mjs')
|
|
29
18
|
}
|
|
19
|
+
await Promise.all(Object.keys(cssThemeMap).map(sideRefreshName => {
|
|
20
|
+
if (!cssThemeMap[sideRefreshName]) {
|
|
21
|
+
throw new Error('invalid side refresh name' + sideRefreshName)
|
|
22
|
+
}
|
|
23
|
+
return import(cssThemeMap[sideRefreshName]).then(m => {
|
|
24
|
+
const mod = m.default || m
|
|
25
|
+
sideRefreshThemes[`${sideRefreshName}_dark`] = mod.themeIsDarkMode
|
|
26
|
+
sideRefreshThemes[`${sideRefreshName}_free`] = mod.themeIsFreeMode
|
|
27
|
+
sideRefreshThemes[`${sideRefreshName}_light`] = mod.themeIsNotDarkMode
|
|
28
|
+
})
|
|
29
|
+
}))
|
|
30
30
|
const folderRegex = new RegExp(Object.keys(sideRefreshThemes).map(capName => parentDir + '/' + capName.split('_')[0]).join('|'))
|
|
31
31
|
return (cap, id, next) => {
|
|
32
32
|
const match = id.match(folderRegex)?.[0]
|
|
@@ -62,7 +62,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
|
|
|
62
62
|
const projectDir = path.join(projectPath, 'src/')
|
|
63
63
|
const projectDirs = fs.readdirSync(projectDir).map(x => x.replace(/\.[jt]sx?$/, ''))
|
|
64
64
|
return {
|
|
65
|
-
async resolve
|
|
65
|
+
async resolve(id, from) {
|
|
66
66
|
if (projectDirs.some(dir => id.startsWith(dir))) {
|
|
67
67
|
try {
|
|
68
68
|
const resolution = await this.resolve(projectDir + id, from, { skipSelf: true })
|
|
@@ -83,7 +83,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
|
|
|
83
83
|
['@' + dirname]: path.join(projectPath, 'src'),
|
|
84
84
|
[aliasImport || '@' + dirname]: path.join(projectPath, 'src')
|
|
85
85
|
},
|
|
86
|
-
shouldResolve
|
|
86
|
+
shouldResolve(from) {
|
|
87
87
|
return from.includes(dirname)
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -95,7 +95,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
|
|
|
95
95
|
const viewer = (iViewer && makeResolver('viewer')) || makeNoopResolver()
|
|
96
96
|
const superkit = (iSuperkit && makeResolver('superkit')) || makeNoopResolver()
|
|
97
97
|
const kit = (iKit && makeResolver('lls-kit', '@kit')) || makeNoopResolver()
|
|
98
|
-
const utils = (iUtils && makeResolver('utils', '
|
|
98
|
+
const utils = (iUtils && makeResolver('utils', '@utils')) || makeNoopResolver()
|
|
99
99
|
const core = (iCore && makeResolver('core', '@core')) || makeNoopResolver()
|
|
100
100
|
const code = (iCode && makeResolver('lls-code', '@code')) || makeNoopResolver()
|
|
101
101
|
const audio = (iAudio && makeResolver('lls-audio', '@audio')) || makeNoopResolver()
|
|
@@ -114,7 +114,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
|
|
|
114
114
|
}))
|
|
115
115
|
const plugin = () => ({
|
|
116
116
|
name: 'lls:sideRefresh',
|
|
117
|
-
async resolveId
|
|
117
|
+
async resolveId(id, from) {
|
|
118
118
|
const basename = path.basename(id)
|
|
119
119
|
if (['core.css', 'viewer.css', 'superkit.css', 'lls-kit.css', 'lls-kit-fonts.css', 'lls-audio.css', 'lls-code.css', 'lls-audio.css'].includes(basename)) {
|
|
120
120
|
return VIRTUAL_ID + key(basename)
|
|
@@ -128,7 +128,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
|
|
|
128
128
|
if (audio.shouldResolve(from)) { return audio.resolve.call(this, id, from) }
|
|
129
129
|
},
|
|
130
130
|
|
|
131
|
-
async load
|
|
131
|
+
async load(id) {
|
|
132
132
|
if (loads.has(id)) {
|
|
133
133
|
return loads.get(id)()
|
|
134
134
|
}
|