@lls/vitescripts 2.0.23 → 24.0.0-2029ab714
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 +14 -14
- package/src/esbuildCssModulePlugin.mjs +1 -1
- package/src/index.mjs +0 -1
- package/src/llsAssetsPlugin.mjs +21 -0
- package/src/llsSideRefreshMetaPlugin.mjs +26 -25
- package/src/llsRequirePlugin.mjs +0 -26
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lls/vitescripts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "24.0.0-2029ab714",
|
|
4
4
|
"description": "lls vite plugins",
|
|
5
5
|
"main": "src/index.mjs",
|
|
6
6
|
"files": [
|
|
7
7
|
"src/"
|
|
8
8
|
],
|
|
9
|
-
"scripts": {
|
|
10
|
-
"test": "CONF_ENV=test npx vitest run",
|
|
11
|
-
"postinstall": "test \"$INIT_CWD\" = \"$PWD\" && npx husky install || echo 'Skipping postinstall'"
|
|
12
|
-
},
|
|
13
9
|
"dependencies": {
|
|
14
|
-
"
|
|
10
|
+
"browserslist": "4.22.1",
|
|
15
11
|
"esbuild-plugin-lightningcss-modules": "0.1.1",
|
|
16
|
-
"
|
|
12
|
+
"lightningcss": "1.22.1"
|
|
17
13
|
},
|
|
18
14
|
"type": "module",
|
|
19
15
|
"author": "",
|
|
20
16
|
"license": "ISC",
|
|
21
17
|
"devDependencies": {
|
|
22
|
-
"@lls/
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"vitest": "0.
|
|
18
|
+
"@lls/lls-kit": "23.0.0",
|
|
19
|
+
"lodash": "4.17.21",
|
|
20
|
+
"nano-staged": "0.8.0",
|
|
21
|
+
"vitest": "1.0.4"
|
|
26
22
|
},
|
|
27
|
-
"
|
|
28
|
-
"
|
|
23
|
+
"nano-staged": {
|
|
24
|
+
"*.{js,jsx,mjs,tsx,ts}": "pnpm vitest related --run"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "pnpm vitest run",
|
|
28
|
+
"precommit": "pnpm nano-staged"
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
}
|
|
@@ -23,9 +23,9 @@ export default ({ prefix = '', llsCssModuleMacroPluginArg }) => {
|
|
|
23
23
|
})
|
|
24
24
|
build.onLoad({ filter: /module\.css$/ }, async args => {
|
|
25
25
|
if (args.path.startsWith(tmpDir)) return
|
|
26
|
+
|
|
26
27
|
const contents = await fs.promises.readFile(args.path, 'utf8').then(str => llsCssModuleMacroPluginInstance.transform(str, args.path))
|
|
27
28
|
const id = args.path.replace(process.cwd(), '').replace(/\//g, '_')
|
|
28
|
-
|
|
29
29
|
const out = path.join(tmpDir, id)
|
|
30
30
|
await fs.promises.writeFile(out, contents)
|
|
31
31
|
return {
|
package/src/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { default as llsAssetsPlugin } from './llsAssetsPlugin.mjs'
|
|
2
2
|
export { default as llsLinariaImportsPlugin } from './llsLinariaImportsPlugin.mjs'
|
|
3
3
|
export { default as llsCssSsrCollectPlugin } from './llsCssSsrCollectPlugin.mjs'
|
|
4
|
-
export { default as llsRequirePlugin } from './llsRequirePlugin.mjs'
|
|
5
4
|
export { default as llsSideRefreshMetaPlugin } from './llsSideRefreshMetaPlugin.mjs'
|
|
6
5
|
export { default as llsVitestMockPlugin } from './llsVitestMockPlugin.mjs'
|
|
7
6
|
export { default as llsLadlePlugin } from './llsLadlePlugin.mjs'
|
package/src/llsAssetsPlugin.mjs
CHANGED
|
@@ -17,12 +17,33 @@ const llsAssetsPlugin = (llsRepos, publicDir = 'ladleassets', { stripRoot = true
|
|
|
17
17
|
const fileExists = (s) => new Promise(resolve => fs.access(s, e => resolve(!e)))
|
|
18
18
|
const srcRoot = process.cwd() + '/src'
|
|
19
19
|
const storyRoot = process.cwd() + '/stories'
|
|
20
|
+
|
|
21
|
+
if (process.env.VITEST) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
20
24
|
return {
|
|
21
25
|
name: 'lls:copyassets',
|
|
22
26
|
async config () {
|
|
23
27
|
await execP(`mkdir -p ${publicAssetDir}`)
|
|
28
|
+
const pnpmNameToPath = await execP('pnpm ls -r @lls/lls-drawer --json'/*'pnpm ls -r -d 0 --json'*/)
|
|
29
|
+
.then(({ stdout }) => JSON.parse(stdout))
|
|
30
|
+
.then(json => {
|
|
31
|
+
let drawer = null
|
|
32
|
+
const back = json.map(({ name, path, dependencies }) => {
|
|
33
|
+
if (dependencies?.['@lls/lls-drawer']?.path) {
|
|
34
|
+
drawer = ['@lls/lls-drawer', dependencies?.['@lls/lls-drawer']?.path + '/lib/assets/*']
|
|
35
|
+
}
|
|
36
|
+
return [name, path + '/lib/assets/*']
|
|
37
|
+
})
|
|
38
|
+
return back.concat(drawer ? [drawer] : [])
|
|
39
|
+
})
|
|
40
|
+
.then(Object.fromEntries)
|
|
41
|
+
.catch(e => {})
|
|
24
42
|
const repoArgs = await Promise.all(llsRepos.map(async repo => {
|
|
25
43
|
if (!repo.startsWith('@')) return repo
|
|
44
|
+
const pnpmPath = pnpmNameToPath[repo]
|
|
45
|
+
if (pnpmPath) return pnpmPath
|
|
46
|
+
|
|
26
47
|
const aPath = 'lib/assets/*'
|
|
27
48
|
const prefix = await fileExists(`${process.cwd()}/node_modules/${repo}`)
|
|
28
49
|
? `${process.cwd()}/node_modules/${repo}`
|
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
3
|
|
|
4
|
+
const toLocal = pkgName => new URL(pkgName, import.meta.url).pathname
|
|
5
|
+
const pwd = toLocal('../')
|
|
6
|
+
|
|
4
7
|
// sideRefreshActiveModules is of the form ['viewer', 'superkit', ...] with 'viewer' if repo launched
|
|
5
8
|
// WITH_VIEWER=1 npm start
|
|
6
9
|
export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules) => {
|
|
7
10
|
const parentDir = path.basename(path.dirname(process.cwd()))
|
|
8
11
|
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
|
-
}))
|
|
12
|
+
const cssThemeMap = {
|
|
13
|
+
viewer: path.join(pwd, '../viewer/src/utils/css-bare.mjs'),
|
|
14
|
+
// kit: no themes for kit
|
|
15
|
+
superkit: path.join(pwd, '../superkit/src/internals/utils/css-bare.mjs'),
|
|
16
|
+
core: path.join(pwd, '../core/src/utils/css-bare.mjs'),
|
|
17
|
+
audio: path.join(pwd, '../lls-audio/src/utils/css-bare.mjs'),
|
|
18
|
+
code: path.join(pwd, '../lls-code/src/utils/css-bare.mjs')
|
|
29
19
|
}
|
|
20
|
+
await Promise.all(Object.keys(cssThemeMap).map(sideRefreshName => {
|
|
21
|
+
if (!cssThemeMap[sideRefreshName]) {
|
|
22
|
+
throw new Error('invalid side refresh name' + sideRefreshName)
|
|
23
|
+
}
|
|
24
|
+
return import(cssThemeMap[sideRefreshName]).then(m => {
|
|
25
|
+
const mod = m.default || m
|
|
26
|
+
sideRefreshThemes[`${sideRefreshName}_dark`] = mod.themeIsDarkMode
|
|
27
|
+
sideRefreshThemes[`${sideRefreshName}_free`] = mod.themeIsFreeMode
|
|
28
|
+
sideRefreshThemes[`${sideRefreshName}_light`] = mod.themeIsNotDarkMode
|
|
29
|
+
})
|
|
30
|
+
}))
|
|
30
31
|
const folderRegex = new RegExp(Object.keys(sideRefreshThemes).map(capName => parentDir + '/' + capName.split('_')[0]).join('|'))
|
|
31
32
|
return (cap, id, next) => {
|
|
32
33
|
const match = id.match(folderRegex)?.[0]
|
|
@@ -62,7 +63,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
|
|
|
62
63
|
const projectDir = path.join(projectPath, 'src/')
|
|
63
64
|
const projectDirs = fs.readdirSync(projectDir).map(x => x.replace(/\.[jt]sx?$/, ''))
|
|
64
65
|
return {
|
|
65
|
-
async resolve
|
|
66
|
+
async resolve(id, from) {
|
|
66
67
|
if (projectDirs.some(dir => id.startsWith(dir))) {
|
|
67
68
|
try {
|
|
68
69
|
const resolution = await this.resolve(projectDir + id, from, { skipSelf: true })
|
|
@@ -83,7 +84,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
|
|
|
83
84
|
['@' + dirname]: path.join(projectPath, 'src'),
|
|
84
85
|
[aliasImport || '@' + dirname]: path.join(projectPath, 'src')
|
|
85
86
|
},
|
|
86
|
-
shouldResolve
|
|
87
|
+
shouldResolve(from) {
|
|
87
88
|
return from.includes(dirname)
|
|
88
89
|
}
|
|
89
90
|
}
|
|
@@ -95,7 +96,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
|
|
|
95
96
|
const viewer = (iViewer && makeResolver('viewer')) || makeNoopResolver()
|
|
96
97
|
const superkit = (iSuperkit && makeResolver('superkit')) || makeNoopResolver()
|
|
97
98
|
const kit = (iKit && makeResolver('lls-kit', '@kit')) || makeNoopResolver()
|
|
98
|
-
const utils = (iUtils && makeResolver('utils', '
|
|
99
|
+
const utils = (iUtils && makeResolver('utils', '@utils')) || makeNoopResolver()
|
|
99
100
|
const core = (iCore && makeResolver('core', '@core')) || makeNoopResolver()
|
|
100
101
|
const code = (iCode && makeResolver('lls-code', '@code')) || makeNoopResolver()
|
|
101
102
|
const audio = (iAudio && makeResolver('lls-audio', '@audio')) || makeNoopResolver()
|
|
@@ -114,7 +115,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
|
|
|
114
115
|
}))
|
|
115
116
|
const plugin = () => ({
|
|
116
117
|
name: 'lls:sideRefresh',
|
|
117
|
-
async resolveId
|
|
118
|
+
async resolveId(id, from) {
|
|
118
119
|
const basename = path.basename(id)
|
|
119
120
|
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
121
|
return VIRTUAL_ID + key(basename)
|
|
@@ -128,7 +129,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
|
|
|
128
129
|
if (audio.shouldResolve(from)) { return audio.resolve.call(this, id, from) }
|
|
129
130
|
},
|
|
130
131
|
|
|
131
|
-
async load
|
|
132
|
+
async load(id) {
|
|
132
133
|
if (loads.has(id)) {
|
|
133
134
|
return loads.get(id)()
|
|
134
135
|
}
|
package/src/llsRequirePlugin.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin using vite-plugin-require-transform, used to transform require syntax to import
|
|
3
|
-
* Needed when we use viewer in sideRefresh
|
|
4
|
-
* @returns the plugin with its transform method
|
|
5
|
-
*/
|
|
6
|
-
const llsSsrRequirePlugin = async () => {
|
|
7
|
-
const VitePluginRequireTransform = await import('vite-plugin-require-transform').then(m => m.default)
|
|
8
|
-
// Lazy loaded viewer modules that are using require syntax
|
|
9
|
-
const fileRegex = /(?:(Audio|Playlist|Recorder|Python|Video|QuestionRich|CodemirrorEditor|useLazyModule)\.jsx$|@lls_lls-code)/
|
|
10
|
-
const back = VitePluginRequireTransform({ fileRegex })
|
|
11
|
-
return {
|
|
12
|
-
name: 'lls:require',
|
|
13
|
-
transform: async function (code, id) {
|
|
14
|
-
const { transform } = await back
|
|
15
|
-
if (fileRegex.test(id)) {
|
|
16
|
-
code = code.replace(/interop\(require\(['"][^'"]+\.browser['"]\)\)/, '() => null')
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
...await transform.apply(this, [code, id]),
|
|
20
|
-
map: null
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default llsSsrRequirePlugin
|