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