@lls/vitescripts 1.0.1 → 1.1.1
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 +5 -2
- package/src/llsAssetsPlugin.mjs +8 -3
- package/src/llsLadlePlugin.mjs +1 -9
- package/src/llsLinariaImportsPlugin.mjs +0 -8
- package/src/llsLinariaSsrCollectPlugin.mjs +15 -13
- package/src/llsRequirePlugin.mjs +7 -8
- package/src/llsSideRefreshMetaPlugin.mjs +49 -39
- package/src/llsVitestMockPlugin.mjs +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lls/vitescripts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "lls vite plugins",
|
|
5
5
|
"main": "src/index.mjs",
|
|
6
6
|
"files": [
|
|
@@ -14,5 +14,8 @@
|
|
|
14
14
|
},
|
|
15
15
|
"type": "module",
|
|
16
16
|
"author": "",
|
|
17
|
-
"license": "ISC"
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@lls/eslint-config-lls": "1.1.12"
|
|
20
|
+
}
|
|
18
21
|
}
|
package/src/llsAssetsPlugin.mjs
CHANGED
|
@@ -2,11 +2,16 @@ import fs from 'fs'
|
|
|
2
2
|
import { promisify } from 'util'
|
|
3
3
|
import { exec } from 'node:child_process'
|
|
4
4
|
import path from 'path'
|
|
5
|
-
import VitePluginRequireTransform from 'vite-plugin-require-transform'
|
|
6
5
|
const execP = promisify(exec)
|
|
7
|
-
const pwd = process.cwd()
|
|
8
6
|
|
|
9
7
|
// https://github.com/vitejs/vite/pull/8574
|
|
8
|
+
/**
|
|
9
|
+
* Plugin that will copy assets from given repos to public dir of launched project
|
|
10
|
+
* @param {*} llsRepos array containing names of the repos
|
|
11
|
+
* @param {*} publicDir public dir to copy assets to
|
|
12
|
+
* @returns config() method that copies assets
|
|
13
|
+
* transform() method that replaces assets path to be resolved
|
|
14
|
+
*/
|
|
10
15
|
const llsAssetsPlugin = (llsRepos, publicDir = 'ladleassets') => {
|
|
11
16
|
const publicAssetDir = path.join(publicDir, 'assets')
|
|
12
17
|
const fileExists = (s) => new Promise(resolve => fs.access(s, e => resolve(!e)))
|
|
@@ -14,7 +19,7 @@ const llsAssetsPlugin = (llsRepos, publicDir = 'ladleassets') => {
|
|
|
14
19
|
const storyRoot = process.cwd() + '/stories'
|
|
15
20
|
return {
|
|
16
21
|
name: 'lls:copyassets',
|
|
17
|
-
async config(
|
|
22
|
+
async config() {
|
|
18
23
|
await execP(`mkdir -p ${publicAssetDir}`)
|
|
19
24
|
const repoArgs = await Promise.all(llsRepos.map(async repo => {
|
|
20
25
|
if (!repo.startsWith('@')) return repo
|
package/src/llsLadlePlugin.mjs
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import { promisify } from 'util'
|
|
3
|
-
import { exec } from 'node:child_process'
|
|
4
|
-
import path from 'path'
|
|
5
|
-
import VitePluginRequireTransform from 'vite-plugin-require-transform'
|
|
6
|
-
const execP = promisify(exec)
|
|
7
|
-
const pwd = process.cwd()
|
|
8
|
-
|
|
9
1
|
const llsLadlePlugin = (sbFolder) => ({
|
|
10
2
|
name: 'lls:llsLadlePlugin',
|
|
11
3
|
config(config, { command }) {
|
|
@@ -21,4 +13,4 @@ const llsLadlePlugin = (sbFolder) => ({
|
|
|
21
13
|
}
|
|
22
14
|
})
|
|
23
15
|
|
|
24
|
-
export default llsLadlePlugin
|
|
16
|
+
export default llsLadlePlugin
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import { promisify } from 'util'
|
|
3
|
-
import { exec } from 'node:child_process'
|
|
4
|
-
import path from 'path'
|
|
5
|
-
import VitePluginRequireTransform from 'vite-plugin-require-transform'
|
|
6
|
-
const execP = promisify(exec)
|
|
7
|
-
const pwd = process.cwd()
|
|
8
|
-
|
|
9
1
|
const llsLinariaImports = () => {
|
|
10
2
|
return {
|
|
11
3
|
name: 'lls:linaria-imports',
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const pwd = process.cwd()
|
|
8
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Plugin that collects styles from linaria cache to inject it in the page.
|
|
3
|
+
* @returns config() method that instantiates linariaPlugin
|
|
4
|
+
* resolveId() method that filters files to be added to css set
|
|
5
|
+
* flushStyles() method that generates and return <style> tag with refreshed style
|
|
6
|
+
*/
|
|
9
7
|
const llsLinariaSsrCollectPlugin = () => {
|
|
10
8
|
const cssIds = new Set()
|
|
11
9
|
let linariaPlugin
|
|
12
10
|
return {
|
|
13
11
|
name: 'lls:llsLinariaSsrCollect',
|
|
14
|
-
config
|
|
12
|
+
config(config) {
|
|
15
13
|
linariaPlugin = config.plugins.find(plugin => plugin.name === 'linaria')
|
|
16
14
|
},
|
|
17
15
|
async resolveId(id, from) {
|
|
18
|
-
if (id.includes('@linaria-cache')) { cssIds.add(id)
|
|
16
|
+
if (id.includes('@linaria-cache')) { cssIds.add(id) }
|
|
19
17
|
},
|
|
18
|
+
flushStyles() {
|
|
19
|
+
const back = `<style id="linaria-ssr-collect-plugin">${[...cssIds].map(linariaPlugin.load).join('\n')}</style>`
|
|
20
|
+
// linaria plugin keeps cache. But we dont want to keep ids which have changed (updating a css component)
|
|
21
|
+
// css is removed from client anyway but still be accurate
|
|
22
|
+
cssIds.clear()
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
return `<style>${[...cssIds].map(linariaPlugin.load).join('\n')}</style>`
|
|
24
|
+
return back
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
export default llsLinariaSsrCollectPlugin
|
|
29
|
+
export default llsLinariaSsrCollectPlugin
|
package/src/llsRequirePlugin.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import { promisify } from 'util'
|
|
3
|
-
import { exec } from 'node:child_process'
|
|
4
|
-
import path from 'path'
|
|
5
1
|
import VitePluginRequireTransform from 'vite-plugin-require-transform'
|
|
6
|
-
const execP = promisify(exec)
|
|
7
|
-
const pwd = process.cwd()
|
|
8
2
|
|
|
9
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Plugin using vite-plugin-require-transform, used to transform require syntax to import
|
|
5
|
+
* Needed when we use viewer in sideRefresh
|
|
6
|
+
* @returns the plugin with its transform method
|
|
7
|
+
*/
|
|
10
8
|
const llsSsrRequirePlugin = () => {
|
|
9
|
+
// Lazy loaded viewer modules that are using require syntax
|
|
11
10
|
const fileRegex = /(?:(Audio|Recorder|Python|Video|QuestionRich|CodemirrorEditor|useLazyModule)\.jsx$|@lls_lls-code)/
|
|
12
11
|
const back = VitePluginRequireTransform({ fileRegex })
|
|
13
12
|
return {
|
|
@@ -25,4 +24,4 @@ const llsSsrRequirePlugin = () => {
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
export default llsSsrRequirePlugin
|
|
27
|
+
export default llsSsrRequirePlugin
|
|
@@ -1,42 +1,50 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
|
-
import { promisify } from 'util'
|
|
3
|
-
import { exec } from 'node:child_process'
|
|
4
2
|
import path from 'path'
|
|
5
|
-
import VitePluginRequireTransform from 'vite-plugin-require-transform'
|
|
6
|
-
const execP = promisify(exec)
|
|
7
3
|
const pwd = process.cwd()
|
|
8
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Side refresh plugin for LLS clients
|
|
7
|
+
* @param {*} param specifies which dependency is beign sideRefreshed
|
|
8
|
+
* @returns a plugin to pass to vite and aliases for sideRefreshed packages
|
|
9
|
+
*/
|
|
10
|
+
const llsSideRefreshMetaPlugin = ({ viewer: iViewer, superkit: iSuperkit, kit: iKit, utils: iUtils }) => {
|
|
11
|
+
if (!iViewer && !iSuperkit && !iKit && !iUtils) { return { plugin: () => false, alias: {} } }
|
|
12
|
+
// eslint-disable-next-line no-console
|
|
13
|
+
console.log('sideResfresh: ', [
|
|
14
|
+
iViewer && 'viewer',
|
|
15
|
+
iSuperkit && 'superkit',
|
|
16
|
+
iKit && 'kit',
|
|
17
|
+
iUtils && 'utils']
|
|
18
|
+
.filter(Boolean))
|
|
9
19
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}) => {
|
|
15
|
-
if (!iViewer && !iSuperkit && !iKit) { return { plugin: () => false, alias: {} } }
|
|
16
|
-
console.log('sideResfresh: ', [iViewer && 'viewer', iSuperkit && 'superkit', iKit && 'lls-kit'].filter(Boolean))
|
|
17
|
-
const makeResolver = dirname => {
|
|
18
|
-
const viewerPath = path.resolve(pwd, '../', dirname)
|
|
19
|
-
const viewerDir = path.join(viewerPath, 'src/')
|
|
20
|
-
const viewerDirs = fs.readdirSync(viewerDir).map(x => x.replace(/\.[jt]sx?$/,''))
|
|
20
|
+
const makeResolver = (dirname, aliasImport) => {
|
|
21
|
+
const projectPath = path.resolve(pwd, '../', dirname)
|
|
22
|
+
const projectDir = path.join(projectPath, 'src/')
|
|
23
|
+
const projectDirs = fs.readdirSync(projectDir).map(x => x.replace(/\.[jt]sx?$/, ''))
|
|
21
24
|
return {
|
|
22
|
-
async resolve
|
|
23
|
-
if (
|
|
25
|
+
async resolve(id, from) {
|
|
26
|
+
if (projectDirs.some(dir => id.startsWith(dir))) {
|
|
24
27
|
try {
|
|
25
|
-
const resolution = await this.resolve(
|
|
28
|
+
const resolution = await this.resolve(projectDir + id, from, { skipSelf: true })
|
|
26
29
|
return resolution.id
|
|
27
30
|
} catch (e) {
|
|
28
|
-
return
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
},
|
|
32
34
|
alias: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
// kit has no public/assets folder, and should fallback to next case (/lib)
|
|
36
|
+
...(dirname === 'lls-kit'
|
|
37
|
+
? {}
|
|
38
|
+
: { ['@lls/' + dirname + '/lib/assets']: path.join(projectPath, 'public/assets') }
|
|
39
|
+
),
|
|
40
|
+
// handle multiple cases : @lls/superkit/lib, @lls/superkit, @superkit, or alias import
|
|
41
|
+
['@lls/' + dirname + '/lib']: path.join(projectPath, 'src'),
|
|
42
|
+
['@lls/' + dirname]: path.join(projectPath, 'src/index'),
|
|
43
|
+
['@' + dirname]: path.join(projectPath, 'src'),
|
|
44
|
+
[aliasImport || '@' + dirname]: path.join(projectPath, 'src')
|
|
37
45
|
},
|
|
38
|
-
shouldResolve
|
|
39
|
-
return from.includes(dirname)
|
|
46
|
+
shouldResolve(from) {
|
|
47
|
+
return from.includes(dirname)
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
50
|
}
|
|
@@ -44,35 +52,37 @@ const llsSideRefreshMetaPlugin = ({
|
|
|
44
52
|
shouldResolve: () => false,
|
|
45
53
|
alias: {}
|
|
46
54
|
})
|
|
47
|
-
const viewer = iViewer && makeResolver('viewer') || makeNoopResolver()
|
|
48
|
-
const superkit = iSuperkit && makeResolver('superkit') || makeNoopResolver()
|
|
49
|
-
const kit = iKit && makeResolver('lls-kit') || makeNoopResolver()
|
|
50
|
-
|
|
55
|
+
const viewer = (iViewer && makeResolver('viewer')) || makeNoopResolver()
|
|
56
|
+
const superkit = (iSuperkit && makeResolver('superkit')) || makeNoopResolver()
|
|
57
|
+
const kit = (iKit && makeResolver('lls-kit', '@kit')) || makeNoopResolver()
|
|
58
|
+
const utils = (iUtils && makeResolver('utils', 'commons')) || makeNoopResolver()
|
|
59
|
+
|
|
51
60
|
const plugin = () => ({
|
|
52
61
|
name: 'lls:sideRefresh',
|
|
53
|
-
async resolveId
|
|
62
|
+
async resolveId(id, from) {
|
|
63
|
+
// viewer.css, superkit.css etc.. are part of the assets so they should not be resolved in project folder
|
|
54
64
|
if (id.endsWith('viewer.css') && from.includes('viewer')) { return 'llslinaria' }
|
|
55
65
|
if (id.endsWith('superkit.css') && from.includes('superkit')) { return 'llslinaria' }
|
|
56
|
-
if (id.endsWith('lls-kit.css') && from.includes('lls-kit')) { return 'llslinaria' }
|
|
66
|
+
if ((id.endsWith('lls-kit.css') || id.endsWith('lls-kit-fonts.css')) && from.includes('lls-kit')) { return 'llslinaria' }
|
|
67
|
+
|
|
68
|
+
if (id.includes('@linaria-cache')) { return }
|
|
57
69
|
if (viewer.shouldResolve(from)) { return viewer.resolve.call(this, id, from) }
|
|
58
70
|
if (superkit.shouldResolve(from)) { return superkit.resolve.call(this, id, from) }
|
|
59
71
|
if (kit.shouldResolve(from)) { return kit.resolve.call(this, id, from) }
|
|
72
|
+
if (utils.shouldResolve(from)) { return utils.resolve.call(this, id, from) }
|
|
60
73
|
},
|
|
61
74
|
|
|
62
|
-
load
|
|
75
|
+
load(id) {
|
|
63
76
|
if (id === 'llslinaria') { return '' }
|
|
64
77
|
}
|
|
65
78
|
})
|
|
66
79
|
const alias = {
|
|
67
80
|
...viewer.alias,
|
|
68
|
-
...superkit.alias
|
|
81
|
+
...superkit.alias,
|
|
82
|
+
...kit.alias,
|
|
83
|
+
...utils.alias
|
|
69
84
|
}
|
|
70
|
-
plugin.ssrOptions = { noExternal: [
|
|
71
|
-
iViewer && '@lls/viewer',
|
|
72
|
-
iSuperkit && '@lls/superkit',
|
|
73
|
-
iKit && '@lls/lls-kit'
|
|
74
|
-
].filter(Boolean) }
|
|
75
85
|
return { plugin, alias }
|
|
76
86
|
}
|
|
77
87
|
|
|
78
|
-
export default llsSideRefreshMetaPlugin
|
|
88
|
+
export default llsSideRefreshMetaPlugin
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import { promisify } from 'util'
|
|
3
|
-
import { exec } from 'node:child_process'
|
|
4
|
-
import path from 'path'
|
|
5
|
-
import VitePluginRequireTransform from 'vite-plugin-require-transform'
|
|
6
|
-
const execP = promisify(exec)
|
|
7
|
-
const pwd = process.cwd()
|
|
8
|
-
|
|
9
1
|
const llsVitestMock = () => ({
|
|
10
2
|
name: 'lls:vitestmock',
|
|
11
3
|
transform(code, id) {
|