jiek 2.3.3 → 2.3.4

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.
Files changed (77) hide show
  1. package/dist/.internal/.chunks/{filterSupport.4rM7f6jB.cjs → getWD.Bdo2NGCR.cjs} +30 -30
  2. package/dist/.internal/.chunks/{filterSupport.BXWpLBpT.js → getWD.DGvwAHMY.js} +29 -29
  3. package/dist/.internal/.chunks/{loadConfig.OOKddvHF.cjs → loadConfig.8xhNFEJe.cjs} +30 -12
  4. package/dist/.internal/.chunks/{loadConfig.CFfzkm_p.js → loadConfig.BjzxLOdC.js} +26 -9
  5. package/dist/.internal/bin/common.cjs +90 -97
  6. package/dist/.internal/bin/common.js +91 -98
  7. package/dist/.internal/bin/parseArgv.cjs +2 -2
  8. package/dist/.internal/bin/parseArgv.js +2 -2
  9. package/dist/.internal/commands/utils/createAreaManagement.cjs +108 -0
  10. package/dist/.internal/commands/utils/createAreaManagement.d.cts +18 -0
  11. package/dist/.internal/commands/utils/createAreaManagement.d.ts +18 -0
  12. package/dist/.internal/commands/utils/createAreaManagement.js +106 -0
  13. package/dist/.internal/polyfill.cjs +13 -0
  14. package/dist/.internal/polyfill.d.cts +1 -0
  15. package/dist/.internal/polyfill.d.ts +1 -0
  16. package/dist/.internal/polyfill.js +11 -0
  17. package/dist/.internal/utils/filterSupport.cjs +1 -1
  18. package/dist/.internal/utils/filterSupport.js +2 -2
  19. package/dist/.internal/utils/loadConfig.cjs +3 -3
  20. package/dist/.internal/utils/loadConfig.d.cts +1 -0
  21. package/dist/.internal/utils/loadConfig.d.ts +1 -0
  22. package/dist/.internal/utils/loadConfig.js +4 -4
  23. package/dist/.internal/utils/pascalCase.cjs +5 -0
  24. package/dist/.internal/utils/pascalCase.d.cts +3 -0
  25. package/dist/.internal/utils/pascalCase.d.ts +3 -0
  26. package/dist/.internal/utils/pascalCase.js +3 -0
  27. package/dist/.internal/utils/reveal.cjs +9 -0
  28. package/dist/.internal/utils/reveal.d.cts +3 -0
  29. package/dist/.internal/utils/reveal.d.ts +3 -0
  30. package/dist/.internal/utils/reveal.js +7 -0
  31. package/dist/bin/index.cjs +101 -43
  32. package/dist/index.d.cts +7 -0
  33. package/dist/index.d.ts +7 -0
  34. package/dist/rollup/index.cjs +16 -18
  35. package/dist/rollup/index.js +13 -15
  36. package/package.json +2 -2
  37. package/src/bin/build.cts +0 -5
  38. package/src/bin/common.ts +0 -3
  39. package/src/bin/index.cts +0 -7
  40. package/src/bin/parseArgv.ts +0 -26
  41. package/src/bridge.ts +0 -46
  42. package/src/commands/base.ts +0 -18
  43. package/src/commands/build/analyzer.ts +0 -122
  44. package/src/commands/build/client/analyzer.tsx +0 -121
  45. package/src/commands/build/client/index.ts +0 -26
  46. package/src/commands/build.ts +0 -544
  47. package/src/commands/descriptions.ts +0 -17
  48. package/src/commands/meta.ts +0 -5
  49. package/src/commands/publish.ts +0 -628
  50. package/src/commands/utils/optionParser.ts +0 -4
  51. package/src/index.ts +0 -12
  52. package/src/inner.ts +0 -11
  53. package/src/rollup/base.ts +0 -152
  54. package/src/rollup/bundle-analyzer.ts +0 -62
  55. package/src/rollup/index.ts +0 -893
  56. package/src/rollup/plugins/create-require.ts +0 -23
  57. package/src/rollup/plugins/progress.ts +0 -26
  58. package/src/rollup/plugins/replace.ts +0 -185
  59. package/src/rollup/plugins/skip.ts +0 -21
  60. package/src/rollup/plugins/with-external.ts +0 -23
  61. package/src/rollup/utils/commonOptions.ts +0 -9
  62. package/src/rollup/utils/externalResolver.ts +0 -47
  63. package/src/rollup/utils/globalResolver.ts +0 -13
  64. package/src/rollup/utils/withMinify.ts +0 -18
  65. package/src/rollup-plugin-utils.ts +0 -32
  66. package/src/server.ts +0 -30
  67. package/src/utils/checkDependency.ts +0 -26
  68. package/src/utils/filterSupport.ts +0 -90
  69. package/src/utils/getInternalModuleName.ts +0 -5
  70. package/src/utils/getRoot.ts +0 -14
  71. package/src/utils/getWD.ts +0 -31
  72. package/src/utils/intersection.ts +0 -1
  73. package/src/utils/loadConfig.ts +0 -108
  74. package/src/utils/recursiveListFiles.ts +0 -13
  75. package/src/utils/resolveExports.ts +0 -165
  76. package/src/utils/ts.ts +0 -94
  77. package/src/utils/tsRegister.ts +0 -22
@@ -1,23 +1,26 @@
1
1
  'use strict';
2
2
 
3
+ require('#~/polyfill');
3
4
  var fs = require('node:fs');
4
5
  var node_path = require('node:path');
5
6
  var process = require('node:process');
6
- var entrypoints = require('@jiek/pkger/entrypoints');
7
- var rollupPluginDts = require('@jiek/rollup-plugin-dts');
8
- var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
9
7
  var commonjs = require('@rollup/plugin-commonjs');
10
8
  var inject = require('@rollup/plugin-inject');
11
9
  var json = require('@rollup/plugin-json');
12
10
  var pluginNodeResolve = require('@rollup/plugin-node-resolve');
13
11
  var ts$1 = require('typescript');
12
+ var entrypoints = require('@jiek/pkger/entrypoints');
13
+ var rollupPluginDts = require('@jiek/rollup-plugin-dts');
14
+ var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
14
15
  var bridge = require('#~/bridge');
15
16
  var bundleAnalyzer = require('#~/rollup/bundle-analyzer');
16
17
  var getInternalModuleName = require('#~/utils/getInternalModuleName');
17
18
  var intersection = require('#~/utils/intersection');
18
19
  var loadConfig = require('#~/utils/loadConfig');
20
+ var pascalCase = require('#~/utils/pascalCase');
19
21
  var recursiveListFiles = require('#~/utils/recursiveListFiles');
20
22
  var resolveExports = require('#~/utils/resolveExports');
23
+ var reveal = require('#~/utils/reveal');
21
24
  var ts = require('#~/utils/ts');
22
25
  var rollupPluginUtils = require('jiek/rollup-plugin-utils');
23
26
  var MagicString = require('magic-string');
@@ -120,7 +123,7 @@ var replace = rollupPluginUtils.definePlugin((options = {}) => {
120
123
  allKeys.forEach((key) => {
121
124
  root.findAll(key).forEach((node) => {
122
125
  const { start, end } = node.range();
123
- const newValue = typeof allValues[key] === "function" ? allValues[key]({
126
+ let newValue = typeof allValues[key] === "function" ? allValues[key]({
124
127
  ...ctx,
125
128
  code,
126
129
  mode: "ast-grep",
@@ -136,11 +139,12 @@ var replace = rollupPluginUtils.definePlugin((options = {}) => {
136
139
  }
137
140
  }) : allValues[key];
138
141
  if ([null, void 0, false].includes(newValue)) return;
139
- ms.overwrite(
140
- start.index,
141
- end.index,
142
- newValue
143
- );
142
+ newValue = newValue.toString();
143
+ newValue = newValue.replace(/\$([a-z_\-]+)/gi, (_, [name]) => {
144
+ if (name == null) return _;
145
+ return node.getMatch(name)?.text() ?? _;
146
+ });
147
+ ms.overwrite(start.index, end.index, newValue);
144
148
  });
145
149
  });
146
150
  }
@@ -330,12 +334,6 @@ const resolveOutputControls = (context, output) => ({
330
334
  dts: typeof output?.dts === "boolean" ? output.dts : typeof output?.dts === "function" ? output.dts(context) : true
331
335
  });
332
336
  const resolveWorkspacePath = (p) => node_path.resolve(WORKSPACE_ROOT, p);
333
- const pascalCase = (str) => str.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase()).replace(/(?:^|-)(\w)/g, (_, $1) => $1.toUpperCase());
334
- const reveal = (obj, keys) => keys.reduce((acc, key) => {
335
- if (typeof acc === "string") throw new Error("key not found in exports");
336
- if (!(key in acc)) throw new Error(`key ${key} not found in exports`);
337
- return acc[key];
338
- }, obj);
339
337
  const resolveMinifyOptions = (minifyOptions) => typeof minifyOptions === "string" ? { type: minifyOptions } : minifyOptions ?? { type: "esbuild" };
340
338
  const resolveBuilderOptions = (builder) => typeof builder === "string" ? { type: builder } : builder ?? { type: "esbuild" };
341
339
  const resolvedMinifyOptions = resolveMinifyOptions(build.output?.minifyOptions ?? MINIFY_OPTIONS);
@@ -690,7 +688,7 @@ function template(packageJSON) {
690
688
  imports: internalEntrypoints
691
689
  } = packageJSON;
692
690
  const pkgIsModule = type === "module";
693
- const packageName = pascalCase(name);
691
+ const packageName = pascalCase.pascalCase(name);
694
692
  const leafMap = /* @__PURE__ */ new Map();
695
693
  const inputTags = /* @__PURE__ */ new Map();
696
694
  const inputExports = /* @__PURE__ */ new Map();
@@ -785,8 +783,8 @@ function template(packageJSON) {
785
783
  const exports = inputExports.get(input);
786
784
  keysArr.forEach((keys) => {
787
785
  const [path, ...conditionals] = keys;
788
- const name2 = packageName + (path === "." ? "" : pascalCase(path));
789
- const keyExports = reveal(exports, keys);
786
+ const name2 = packageName + (path === "." ? "" : pascalCase.pascalCase(path));
787
+ const keyExports = reveal.reveal(exports, keys);
790
788
  const commonContext = {
791
789
  path,
792
790
  name: name2,
@@ -1,21 +1,24 @@
1
+ import '#~/polyfill';
1
2
  import fs from 'node:fs';
2
3
  import { extname, relative, resolve, dirname } from 'node:path';
3
4
  import process from 'node:process';
4
- import { getAllLeafs } from '@jiek/pkger/entrypoints';
5
- import { dts } from '@jiek/rollup-plugin-dts';
6
- import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
7
5
  import commonjs from '@rollup/plugin-commonjs';
8
6
  import inject from '@rollup/plugin-inject';
9
7
  import json from '@rollup/plugin-json';
10
8
  import { nodeResolve } from '@rollup/plugin-node-resolve';
11
9
  import ts from 'typescript';
10
+ import { getAllLeafs } from '@jiek/pkger/entrypoints';
11
+ import { dts } from '@jiek/rollup-plugin-dts';
12
+ import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
12
13
  import { publish } from '#~/bridge';
13
14
  import { bundleAnalyzer } from '#~/rollup/bundle-analyzer';
14
15
  import { getInternalModuleName } from '#~/utils/getInternalModuleName';
15
16
  import { intersection } from '#~/utils/intersection';
16
17
  import { loadConfig } from '#~/utils/loadConfig';
18
+ import { pascalCase } from '#~/utils/pascalCase';
17
19
  import { recursiveListFiles } from '#~/utils/recursiveListFiles';
18
20
  import { getOutDirs, resolveExports } from '#~/utils/resolveExports';
21
+ import { reveal } from '#~/utils/reveal';
19
22
  import { getCompilerOptionsByFilePath } from '#~/utils/ts';
20
23
  import { createRequire as createRequire$1, builtinModules } from 'node:module';
21
24
  import { definePlugin, createFilter } from 'jiek/rollup-plugin-utils';
@@ -108,7 +111,7 @@ var replace = definePlugin((options = {}) => {
108
111
  allKeys.forEach((key) => {
109
112
  root.findAll(key).forEach((node) => {
110
113
  const { start, end } = node.range();
111
- const newValue = typeof allValues[key] === "function" ? allValues[key]({
114
+ let newValue = typeof allValues[key] === "function" ? allValues[key]({
112
115
  ...ctx,
113
116
  code,
114
117
  mode: "ast-grep",
@@ -124,11 +127,12 @@ var replace = definePlugin((options = {}) => {
124
127
  }
125
128
  }) : allValues[key];
126
129
  if ([null, void 0, false].includes(newValue)) return;
127
- ms.overwrite(
128
- start.index,
129
- end.index,
130
- newValue
131
- );
130
+ newValue = newValue.toString();
131
+ newValue = newValue.replace(/\$([a-z_\-]+)/gi, (_, [name]) => {
132
+ if (name == null) return _;
133
+ return node.getMatch(name)?.text() ?? _;
134
+ });
135
+ ms.overwrite(start.index, end.index, newValue);
132
136
  });
133
137
  });
134
138
  }
@@ -318,12 +322,6 @@ const resolveOutputControls = (context, output) => ({
318
322
  dts: typeof output?.dts === "boolean" ? output.dts : typeof output?.dts === "function" ? output.dts(context) : true
319
323
  });
320
324
  const resolveWorkspacePath = (p) => resolve(WORKSPACE_ROOT, p);
321
- const pascalCase = (str) => str.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase()).replace(/(?:^|-)(\w)/g, (_, $1) => $1.toUpperCase());
322
- const reveal = (obj, keys) => keys.reduce((acc, key) => {
323
- if (typeof acc === "string") throw new Error("key not found in exports");
324
- if (!(key in acc)) throw new Error(`key ${key} not found in exports`);
325
- return acc[key];
326
- }, obj);
327
325
  const resolveMinifyOptions = (minifyOptions) => typeof minifyOptions === "string" ? { type: minifyOptions } : minifyOptions ?? { type: "esbuild" };
328
326
  const resolveBuilderOptions = (builder) => typeof builder === "string" ? { type: builder } : builder ?? { type: "esbuild" };
329
327
  const resolvedMinifyOptions = resolveMinifyOptions(build.output?.minifyOptions ?? MINIFY_OPTIONS);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "2.3.3",
4
+ "version": "2.3.4",
5
5
  "description": "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.",
6
6
  "author": "YiJie <yijie4188@gmail.com>",
7
7
  "homepage": "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme",
@@ -83,7 +83,7 @@
83
83
  "magic-string": "^0.30.17",
84
84
  "rollup": "^4.0.0",
85
85
  "@jiek/pkger": "^0.2.2",
86
- "@jiek/utils": "^0.2.3"
86
+ "@jiek/utils": "^0.2.4"
87
87
  },
88
88
  "peerDependenciesMeta": {
89
89
  "@ast-grep/napi": {
package/src/bin/build.cts DELETED
@@ -1,5 +0,0 @@
1
- import '#~/bin/common'
2
-
3
- import parseArgv from '#~/bin/parseArgv'
4
-
5
- parseArgv()
package/src/bin/common.ts DELETED
@@ -1,3 +0,0 @@
1
- import '../utils/filterSupport'
2
- import '../commands/base'
3
- import '../commands/build'
package/src/bin/index.cts DELETED
@@ -1,7 +0,0 @@
1
- import '#~/bin/common'
2
-
3
- import '../commands/publish'
4
-
5
- import parseArgv from '#~/bin/parseArgv'
6
-
7
- parseArgv()
@@ -1,26 +0,0 @@
1
- import { program } from 'commander'
2
- import process from 'node:process'
3
-
4
- const { argv } = process
5
- const env: Record<string, string> = {}
6
- let isPassThrough = false
7
- const newArgv = argv.filter((arg) => {
8
- if (isPassThrough) {
9
- return true
10
- }
11
- if (arg === '--') {
12
- isPassThrough = true
13
- return false
14
- }
15
- const m = /^--env\.(\w+)=(.*)$/.exec(arg)
16
- if (m) {
17
- env[m[1]] = m[2]
18
- return false
19
- }
20
- return true
21
- })
22
- for (const [key, value] of Object.entries(env)) {
23
- process.env[key] = value
24
- }
25
-
26
- export default () => program.parse(newArgv)
package/src/bridge.ts DELETED
@@ -1,46 +0,0 @@
1
- import type { Module } from '#~/rollup/bundle-analyzer'
2
-
3
- import { sendMessage } from 'execa'
4
-
5
- export const bridgeDisabledRef = { value: false }
6
-
7
- export interface RollupBuildEntryCtx {
8
- type: 'esm' | 'cjs'
9
- name: string
10
- path: string
11
- exportConditions: string[]
12
- input: string
13
- }
14
-
15
- export interface RollupBuildEventMap {
16
- init: {
17
- leafMap: Map<string, string[][]>
18
- targetsLength: number
19
- }
20
- progress: RollupBuildEntryCtx & {
21
- tags?: string[]
22
- event?: string
23
- message?: string
24
- }
25
- watchChange: RollupBuildEntryCtx & {
26
- id: string
27
- }
28
- modulesAnalyze: RollupBuildEntryCtx & {
29
- modules: Module[]
30
- }
31
- debug: unknown
32
- }
33
-
34
- export type RollupBuildEvent = keyof RollupBuildEventMap extends infer K
35
- ? K extends infer Item extends keyof RollupBuildEventMap ? {
36
- type: Item
37
- data: RollupBuildEventMap[Item]
38
- }
39
- : never
40
- : never
41
-
42
- export const publish = async <K extends keyof RollupBuildEventMap>(type: K, data: RollupBuildEventMap[K]) => {
43
- if (bridgeDisabledRef.value) return Promise.resolve()
44
-
45
- return sendMessage({ type, data })
46
- }
@@ -1,18 +0,0 @@
1
- import { program } from 'commander'
2
- import pkg from 'jiek/package.json'
3
-
4
- import { filterDescription } from '#~/commands/descriptions'
5
- import { IS_WORKSPACE } from '#~/commands/meta'
6
- import { type } from '#~/utils/filterSupport'
7
-
8
- program
9
- .name('jk/jiek')
10
- .version(pkg.version)
11
- .description(`${pkg.description} - Version ${pkg.version}`)
12
- .option('-c, --config-path <configPath>', 'Custom jiek config path')
13
- .option('--env.<name>=<value>', 'Set the environment variable.')
14
-
15
- if (type !== '' && IS_WORKSPACE) {
16
- program
17
- .option('-f, --filter <filter>', filterDescription)
18
- }
@@ -1,122 +0,0 @@
1
- import type { Command } from 'commander'
2
-
3
- import { CLIENT_CUSTOM_RENDER_SCRIPT } from '#~/commands/build/client/index'
4
- import { parseBoolean } from '#~/commands/utils/optionParser'
5
- import type { Module } from '#~/rollup/bundle-analyzer'
6
- import type { createServer } from '#~/server'
7
- import { checkDependency } from '#~/utils/checkDependency'
8
- import { existsSync, mkdirSync, statSync, writeFileSync } from 'node:fs'
9
- import path from 'node:path'
10
-
11
- export interface AnalyzerBuildOptions {
12
- ana?: boolean
13
- /**
14
- * @default '.jk-analyses'
15
- */
16
- 'ana.dir': string
17
- /**
18
- * @default 'server'
19
- */
20
- 'ana.mode': string
21
- 'ana.open'?: boolean
22
- /**
23
- * @default 'parsed'
24
- */
25
- 'ana.size': string
26
- }
27
-
28
- export const registerAnalyzerCommandOptions = (command: Command) =>
29
- command
30
- .option('--ana', 'Enable the bundle analyzer.', parseBoolean)
31
- .option('--ana.dir <DIR>', 'The directory of the bundle analyzer.', '.jk-analyses')
32
- .option(
33
- '--ana.mode <MODE>',
34
- 'The mode of the bundle analyzer, support "static", "json" and "server".',
35
- 'server'
36
- )
37
- .option('--ana.open', 'Open the bundle analyzer in the browser.', parseBoolean)
38
- .option(
39
- '--ana.size <SIZE>',
40
- 'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
41
- 'parsed'
42
- )
43
-
44
- export const useAnalyzer = async (options: AnalyzerBuildOptions, server?: ReturnType<typeof createServer>) => {
45
- const modules: Module[] = []
46
- let bundleAnalyzerModule: typeof import('vite-bundle-analyzer') | undefined
47
- const analyzer = options.ana
48
- ? {
49
- dir: options['ana.dir'],
50
- mode: options['ana.mode'],
51
- open: options['ana.open'],
52
- size: options['ana.size']
53
- }
54
- : undefined
55
- if (
56
- options.ana
57
- && ![
58
- 'stat',
59
- 'parsed',
60
- 'gzip'
61
- ].includes(analyzer?.size ?? '')
62
- ) {
63
- throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"')
64
- }
65
-
66
- if (analyzer) {
67
- await checkDependency('vite-bundle-analyzer')
68
- bundleAnalyzerModule = await import('vite-bundle-analyzer')
69
- }
70
-
71
- const refreshAnalyzer = async (cwd: string, applyModules: typeof modules) => {
72
- if (!(analyzer && server && bundleAnalyzerModule)) return
73
-
74
- if (analyzer.mode === 'json') {
75
- const anaDir = path.resolve(cwd, analyzer.dir)
76
- if (!existsSync(anaDir)) {
77
- mkdirSync(anaDir, { recursive: true })
78
- }
79
- const gitIgnorePath = path.resolve(anaDir, '.gitignore')
80
- if (!existsSync(gitIgnorePath)) {
81
- writeFileSync(gitIgnorePath, '*\n!.gitignore\n')
82
- }
83
- const npmIgnorePath = path.resolve(anaDir, '.npmignore')
84
- if (!existsSync(npmIgnorePath)) {
85
- writeFileSync(npmIgnorePath, '*\n')
86
- }
87
- if (!statSync(anaDir).isDirectory()) {
88
- throw new Error(`The directory '${anaDir}' is not a directory.`)
89
- }
90
- }
91
-
92
- const { renderView, injectHTMLTag } = bundleAnalyzerModule
93
- applyModules.forEach(m => {
94
- const index = modules.findIndex(({ filename }) => filename === m.filename)
95
- if (index === -1) {
96
- modules.push(m)
97
- } else {
98
- modules[index] = m
99
- }
100
- })
101
- let html = await renderView(modules, {
102
- title: `Jiek Analyzer`,
103
- mode: analyzer.size as 'stat' | 'parsed' | 'gzip'
104
- })
105
- html = injectHTMLTag({
106
- html,
107
- injectTo: 'body',
108
- descriptors: [
109
- { kind: 'script', text: CLIENT_CUSTOM_RENDER_SCRIPT }
110
- ]
111
- })
112
- void server.renderTo('/ana', html)
113
- }
114
-
115
- return {
116
- modules,
117
- refreshAnalyzer,
118
- ANALYZER_ENV: {
119
- JIEK_ANALYZER: analyzer ? JSON.stringify(analyzer) : undefined
120
- }
121
- }
122
- }
@@ -1,121 +0,0 @@
1
- import type { Module } from '#~/rollup/bundle-analyzer'
2
-
3
- interface Node {
4
- id: string
5
- filename: string
6
- parent?: Node
7
- }
8
-
9
- declare global {
10
- // @ts-ignore
11
- // eslint-disable-next-line no-var,vars-on-top
12
- var React: typeof import('react')
13
- // eslint-disable-next-line no-var,vars-on-top
14
- var analyzeModule: Module[]
15
- interface WindowEventMap {
16
- 'graph:click': CustomEvent<
17
- | undefined
18
- | { node: Node }
19
- >
20
- 'send:filter': CustomEvent<{
21
- analyzeModule: Module[]
22
- }>
23
- }
24
- }
25
-
26
- export function Main() {
27
- const { useState, useMemo, useEffect, useCallback } = React
28
- const [path, setPath] = useState(() => location.pathname.replace(/^\/ana\/?/, ''))
29
- const [pkgName, entry] = useMemo(() => {
30
- const pkgName = /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(path)?.[1]
31
- return [
32
- pkgName,
33
- (pkgName != null) ? path.replace(`${pkgName}/`, '') : undefined
34
- ]
35
- }, [path])
36
- const push = useCallback((newPath: string) => {
37
- setPath(newPath)
38
- document.title = `${document.title.replace(/ - \/.*/, '')} - \/${newPath}`
39
- history.pushState(null, '', `/ana/${newPath}`)
40
- }, [])
41
- const filterModules = useCallback((startWith: string) => {
42
- const modules = analyzeModule.filter(m => m.filename.startsWith(startWith))
43
- dispatchEvent(new CustomEvent('send:filter', { detail: { analyzeModule: modules } }))
44
- }, [])
45
- useEffect(() => {
46
- if (path !== '') {
47
- document.title = `${document.title.replace(/ - \/.*/, '')} - \/${path}`
48
- } else {
49
- document.title = document.title.replace(/ - \/.*/, '')
50
- }
51
- filterModules(path)
52
- }, [path, filterModules])
53
- useEffect(() => {
54
- const offGraphClick = listen('graph:click', ({ detail }) => {
55
- if (!detail) return
56
-
57
- let root = detail.node
58
- while (root.parent) {
59
- root = root.parent
60
- }
61
- if (root.filename === path) return
62
- push(root.filename)
63
- })
64
- return () => {
65
- offGraphClick()
66
- }
67
- }, [push])
68
- function listen<T extends keyof WindowEventMap>(type: T, listener: (this: Window, ev: WindowEventMap[T]) => any) {
69
- window.addEventListener(type, listener)
70
- return () => {
71
- window.removeEventListener(type, listener)
72
- }
73
- }
74
- return (
75
- <div
76
- style={{
77
- padding: '12px 55px'
78
- }}
79
- >
80
- /
81
- <select
82
- style={{
83
- appearance: 'none',
84
- border: 'none',
85
- background: 'none'
86
- }}
87
- value={pkgName}
88
- onChange={e => push(e.target.value)}
89
- >
90
- <option value=''>All</option>
91
- {analyzeModule
92
- .map(m => /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(m.filename)?.[1])
93
- .filter((v, i, a) => a.indexOf(v) === i)
94
- .map(v => (
95
- <option key={v} value={v}>{v}</option>
96
- ))}
97
- </select>
98
- {pkgName != null && <>
99
- /
100
- <select
101
- style={{
102
- appearance: 'none',
103
- border: 'none',
104
- background: 'none'
105
- }}
106
- value={entry}
107
- onChange={e => push(`${pkgName}/${e.target.value}`)}
108
- >
109
- <option value=''>All</option>
110
- {analyzeModule
111
- .filter(m => m.filename.startsWith(`${pkgName}/`))
112
- .map(m => m.filename.replace(`${pkgName}/`, ''))
113
- .filter((v, i, a) => a.indexOf(v) === i)
114
- .map(v => (
115
- <option key={v} value={v}>{v}</option>
116
- ))}
117
- </select>
118
- </>}
119
- </div>
120
- )
121
- }
@@ -1,26 +0,0 @@
1
- import { Main } from './analyzer'
2
-
3
- declare global {
4
- // eslint-disable-next-line no-var,vars-on-top
5
- var CUSTOM_SIDE_BAR: boolean
6
- // eslint-disable-next-line no-var,vars-on-top
7
- var __REPLACE_INJECT__: string
8
- }
9
-
10
- function render() {
11
- CUSTOM_SIDE_BAR = true
12
- window.addEventListener('client:ready', () =>
13
- window.dispatchEvent(
14
- new CustomEvent('send:ui', {
15
- detail: { type: 'Main', Component: __REPLACE_INJECT__ }
16
- })
17
- ))
18
- }
19
-
20
- export const CLIENT_CUSTOM_RENDER_SCRIPT = [
21
- Main.toString(),
22
- render
23
- .toString()
24
- .replace('__REPLACE_INJECT__', Main.name),
25
- `(${render.name})()`
26
- ].join('\n')