@lls/vitescripts 1.0.0 → 1.1.0

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 CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@lls/vitescripts",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "lls vite plugins",
5
5
  "main": "src/index.mjs",
6
- "files": ["src/"],
6
+ "files": [
7
+ "src/"
8
+ ],
7
9
  "scripts": {
8
10
  "test": "echo \"Error: no test specified\" && exit 1"
9
11
  },
@@ -12,5 +14,8 @@
12
14
  },
13
15
  "type": "module",
14
16
  "author": "",
15
- "license": "ISC"
17
+ "license": "ISC",
18
+ "devDependencies": {
19
+ "@lls/eslint-config-lls": "1.1.12"
20
+ }
16
21
  }
package/src/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- export { default as llsAssetsPlugin } from './llsAssetsPlugin'
2
- export { default as llsLinariaImportsPlugin } from './llsLinariaImportsPlugin'
3
- export { default as llsLinariaSsrCollectPlugin } from './llsLinariaSsrCollectPlugin'
4
- export { default as llsRequirePlugin } from './llsRequirePlugin'
5
- export { default as llsSideRefreshMetaPlugin } from './llsSideRefreshMetaPlugin'
6
- export { default as llsVitestMockPlugin } from './llsVitestMock'
7
- export { default as llsLadlePlugin } from './llsLadlePlugin'
1
+ export { default as llsAssetsPlugin } from './llsAssetsPlugin.mjs'
2
+ export { default as llsLinariaImportsPlugin } from './llsLinariaImportsPlugin.mjs'
3
+ export { default as llsLinariaSsrCollectPlugin } from './llsLinariaSsrCollectPlugin.mjs'
4
+ export { default as llsRequirePlugin } from './llsRequirePlugin.mjs'
5
+ export { default as llsSideRefreshMetaPlugin } from './llsSideRefreshMetaPlugin.mjs'
6
+ export { default as llsVitestMockPlugin } from './llsVitestMockPlugin.mjs'
7
+ export { default as llsLadlePlugin } from './llsLadlePlugin.mjs'
@@ -2,9 +2,7 @@ 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
10
8
  const llsAssetsPlugin = (llsRepos, publicDir = 'ladleassets') => {
@@ -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',
@@ -0,0 +1,19 @@
1
+ const llsLinariaSsrCollectPlugin = () => {
2
+ const cssIds = new Set()
3
+ let linariaPlugin
4
+ return {
5
+ name: 'lls:llsLinariaSsrCollect',
6
+ config(config) {
7
+ linariaPlugin = config.plugins.find(plugin => plugin.name === 'linaria')
8
+ },
9
+ async resolveId(id, from) {
10
+ if (id.includes('@linaria-cache')) { cssIds.add(id) }
11
+ },
12
+
13
+ collectSsrStyles() {
14
+ return `<style>${[...cssIds].map(linariaPlugin.load).join('\n')}</style>`
15
+ }
16
+ }
17
+ }
18
+
19
+ export default llsLinariaSsrCollectPlugin
@@ -1,10 +1,4 @@
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
  // needed for viewer if siderefresh
10
4
  const llsSsrRequirePlugin = () => {
@@ -1,42 +1,49 @@
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
+ console.log('sideResfresh: ', [
13
+ iViewer && 'viewer',
14
+ iSuperkit && 'superkit',
15
+ iKit && 'kit',
16
+ iUtils && 'utils']
17
+ .filter(Boolean))
9
18
 
10
- const llsSideRefreshMetaPlugin = ({
11
- viewer: iViewer = process.env.WITH_VIEWER === '1',
12
- superkit: iSuperkit = process.env.WITH_SUPERKIT === '1',
13
- kit: iKit = process.env.WITH_KIT === '1'
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?$/,''))
19
+ const makeResolver = (dirname, aliasImport) => {
20
+ const projectPath = path.resolve(pwd, '../', dirname)
21
+ const projectDir = path.join(projectPath, 'src/')
22
+ const projectDirs = fs.readdirSync(projectDir).map(x => x.replace(/\.[jt]sx?$/, ''))
21
23
  return {
22
- async resolve (id, from) {
23
- if (viewerDirs.some(dir => id.startsWith(dir))) {
24
+ async resolve(id, from) {
25
+ if (projectDirs.some(dir => id.startsWith(dir))) {
24
26
  try {
25
- const resolution = await this.resolve(viewerDir + id, from, { skipSelf: true })
27
+ const resolution = await this.resolve(projectDir + id, from, { skipSelf: true })
26
28
  return resolution.id
27
29
  } catch (e) {
28
- return
29
30
  }
30
31
  }
31
32
  },
32
33
  alias: {
33
- ['@lls/'+dirname+'/lib/assets'] : path.join(viewerPath, 'public/assets'),
34
- ['@lls/'+dirname+'/lib'] : path.join(viewerPath, 'src'),
35
- ['@lls/'+dirname]: path.join(viewerPath, 'src/index.jsx'),
36
- ['@'+dirname]: path.join(viewerPath, 'src')
34
+ // kit has no public/assets folder, and should fallback to next case (/lib)
35
+ ...(dirname === 'lls-kit'
36
+ ? {}
37
+ : { ['@lls/' + dirname + '/lib/assets']: path.join(projectPath, 'public/assets') }
38
+ ),
39
+ // handle multiple cases : @lls/superkit/lib, @lls/superkit, @superkit, or alias import
40
+ ['@lls/' + dirname + '/lib']: path.join(projectPath, 'src'),
41
+ ['@lls/' + dirname]: path.join(projectPath, 'src/index'),
42
+ ['@' + dirname]: path.join(projectPath, 'src'),
43
+ [aliasImport || '@' + dirname]: path.join(projectPath, 'src')
37
44
  },
38
- shouldResolve (from) {
39
- return from.includes(dirname) && !from.includes('webview')
45
+ shouldResolve(from) {
46
+ return from.includes(dirname)
40
47
  }
41
48
  }
42
49
  }
@@ -44,35 +51,37 @@ const llsSideRefreshMetaPlugin = ({
44
51
  shouldResolve: () => false,
45
52
  alias: {}
46
53
  })
47
- const viewer = iViewer && makeResolver('viewer') || makeNoopResolver()
48
- const superkit = iSuperkit && makeResolver('superkit') || makeNoopResolver()
49
- const kit = iKit && makeResolver('lls-kit') || makeNoopResolver()
50
-
54
+ const viewer = (iViewer && makeResolver('viewer')) || makeNoopResolver()
55
+ const superkit = (iSuperkit && makeResolver('superkit')) || makeNoopResolver()
56
+ const kit = (iKit && makeResolver('lls-kit', '@kit')) || makeNoopResolver()
57
+ const utils = (iUtils && makeResolver('utils', 'commons')) || makeNoopResolver()
58
+
51
59
  const plugin = () => ({
52
60
  name: 'lls:sideRefresh',
53
- async resolveId (id, from) {
61
+ async resolveId(id, from) {
62
+ // viewer.css, superkit.css etc.. are part of the assets so they should not be resolved in project folder
54
63
  if (id.endsWith('viewer.css') && from.includes('viewer')) { return 'llslinaria' }
55
64
  if (id.endsWith('superkit.css') && from.includes('superkit')) { return 'llslinaria' }
56
- if (id.endsWith('lls-kit.css') && from.includes('lls-kit')) { return 'llslinaria' }
65
+ if ((id.endsWith('lls-kit.css') || id.endsWith('lls-kit-fonts.css')) && from.includes('lls-kit')) { return 'llslinaria' }
66
+
67
+ if (id.includes('@linaria-cache')) { return }
57
68
  if (viewer.shouldResolve(from)) { return viewer.resolve.call(this, id, from) }
58
69
  if (superkit.shouldResolve(from)) { return superkit.resolve.call(this, id, from) }
59
70
  if (kit.shouldResolve(from)) { return kit.resolve.call(this, id, from) }
71
+ if (utils.shouldResolve(from)) { return utils.resolve.call(this, id, from) }
60
72
  },
61
73
 
62
- load (id) {
74
+ load(id) {
63
75
  if (id === 'llslinaria') { return '' }
64
76
  }
65
77
  })
66
78
  const alias = {
67
79
  ...viewer.alias,
68
- ...superkit.alias
80
+ ...superkit.alias,
81
+ ...kit.alias,
82
+ ...utils.alias
69
83
  }
70
- plugin.ssrOptions = { noExternal: [
71
- iViewer && '@lls/viewer',
72
- iSuperkit && '@lls/superkit',
73
- iKit && '@lls/lls-kit'
74
- ].filter(Boolean) }
75
84
  return { plugin, alias }
76
85
  }
77
86
 
78
- export default llsSideRefreshMetaPlugin
87
+ 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) {
@@ -1,27 +0,0 @@
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
- const llsLinariaSsrCollectPlugin = () => {
10
- const cssIds = new Set()
11
- let linariaPlugin
12
- return {
13
- name: 'lls:llsLinariaSsrCollect',
14
- config (config) {
15
- linariaPlugin = config.plugins.find(plugin => plugin.name === 'linaria')
16
- },
17
- async resolveId(id, from) {
18
- if (id.includes('@linaria-cache')) { cssIds.add(id); return }
19
- },
20
-
21
- collectSsrStyles () {
22
- return `<style>${[...cssIds].map(linariaPlugin.load).join('\n')}</style>`
23
- }
24
- }
25
- }
26
-
27
- export default llsLinariaSsrCollectPlugin