@prosopo/config 0.2.13 → 0.2.14

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 (57) hide show
  1. package/dist/dependencies.js +1 -1
  2. package/dist/polkadot/bytes.d.ts +4 -0
  3. package/dist/polkadot/bytes.d.ts.map +1 -0
  4. package/dist/polkadot/bytes.js +9 -0
  5. package/dist/polkadot/bytes.js.map +1 -0
  6. package/dist/polkadot/exclude.d.ts +0 -1
  7. package/dist/polkadot/exclude.d.ts.map +1 -1
  8. package/dist/polkadot/exclude.js +132 -19
  9. package/dist/polkadot/exclude.js.map +1 -1
  10. package/dist/polkadot/index.d.ts +1 -1
  11. package/dist/polkadot/index.d.ts.map +1 -1
  12. package/dist/polkadot/index.js +1 -1
  13. package/dist/polkadot/index.js.map +1 -1
  14. package/dist/polkadot/mockApiDerive.d.ts +3 -0
  15. package/dist/polkadot/mockApiDerive.d.ts.map +1 -0
  16. package/dist/polkadot/mockApiDerive.js +2 -0
  17. package/dist/polkadot/mockApiDerive.js.map +1 -0
  18. package/dist/polkadot/mockInterface.d.ts +5 -0
  19. package/dist/polkadot/mockInterface.d.ts.map +1 -0
  20. package/dist/polkadot/mockInterface.js +2 -0
  21. package/dist/polkadot/mockInterface.js.map +1 -0
  22. package/dist/polkadot/mockSubstrateGenesis.d.ts +30 -0
  23. package/dist/polkadot/mockSubstrateGenesis.d.ts.map +1 -0
  24. package/dist/polkadot/mockSubstrateGenesis.js +47 -0
  25. package/dist/polkadot/mockSubstrateGenesis.js.map +1 -0
  26. package/dist/polkadot/{mock.d.ts → mockUpgrade.d.ts} +3 -1
  27. package/dist/polkadot/mockUpgrade.d.ts.map +1 -0
  28. package/dist/polkadot/{mock.js → mockUpgrade.js} +3 -1
  29. package/dist/polkadot/mockUpgrade.js.map +1 -0
  30. package/dist/vite/vite.backend.config.d.ts.map +1 -1
  31. package/dist/vite/vite.backend.config.js +12 -2
  32. package/dist/vite/vite.backend.config.js.map +1 -1
  33. package/dist/vite/vite.commonjs.config.d.ts.map +1 -1
  34. package/dist/vite/vite.commonjs.config.js +6 -0
  35. package/dist/vite/vite.commonjs.config.js.map +1 -1
  36. package/dist/vite/vite.frontend.config.d.ts.map +1 -1
  37. package/dist/vite/vite.frontend.config.js +46 -17
  38. package/dist/vite/vite.frontend.config.js.map +1 -1
  39. package/dist/vite/vite.test.config.d.ts.map +1 -1
  40. package/dist/vite/vite.test.config.js +12 -2
  41. package/dist/vite/vite.test.config.js.map +1 -1
  42. package/package.json +9 -8
  43. package/src/dependencies.ts +1 -1
  44. package/src/polkadot/bytes.ts +14 -0
  45. package/src/polkadot/exclude.ts +141 -19
  46. package/src/polkadot/index.ts +1 -1
  47. package/src/polkadot/mockApiDerive.ts +1 -0
  48. package/src/polkadot/mockInterface.ts +1 -0
  49. package/src/polkadot/mockSubstrateGenesis.ts +46 -0
  50. package/src/polkadot/{mock.ts → mockUpgrade.ts} +2 -0
  51. package/src/vite/vite.backend.config.ts +15 -3
  52. package/src/vite/vite.commonjs.config.ts +8 -0
  53. package/src/vite/vite.frontend.config.ts +47 -17
  54. package/src/vite/vite.test.config.ts +12 -2
  55. package/tsconfig.tsbuildinfo +1 -1
  56. package/dist/polkadot/mock.d.ts.map +0 -1
  57. package/dist/polkadot/mock.js.map +0 -1
@@ -1,5 +1,6 @@
1
1
  import { AliasOptions, UserConfig } from 'vite'
2
2
  import { default as ClosePlugin } from './vite-plugin-close-and-copy.js'
3
+ import { Drop } from 'esbuild'
3
4
  import { builtinModules } from 'module'
4
5
  import { filterDependencies, getDependencies } from '../dependencies.js'
5
6
  import { getLogger } from '@prosopo/common'
@@ -47,6 +48,8 @@ export default async function (
47
48
  command?: string,
48
49
  mode?: string
49
50
  ): Promise<UserConfig> {
51
+ const isProduction = mode === 'production'
52
+
50
53
  // Get all dependencies of the current package
51
54
  const { dependencies: deps, optionalPeerDependencies } = await getDependencies(packageName, true)
52
55
 
@@ -68,8 +71,6 @@ export default async function (
68
71
  ...optionalPeerDependencies,
69
72
  ]
70
73
 
71
- console.log('allExternal', allExternal)
72
-
73
74
  logger.info(`Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`)
74
75
 
75
76
  const nodeJsNodeFileToCopy = path.resolve(
@@ -82,6 +83,12 @@ export default async function (
82
83
  'process.env.WS_NO_BUFFER_UTIL': 'true',
83
84
  'process.env.WS_NO_UTF_8_VALIDATE': 'true',
84
85
  'process.env.PROSOPO_PACKAGE_VERSION': JSON.stringify(packageVersion),
86
+ ...(process.env.DEFAULT_ENVIRONMENT && {
87
+ 'process.env.DEFAULT_ENVIRONMENT': JSON.stringify(process.env.DEFAULT_ENVIRONMENT),
88
+ }),
89
+ ...(process.env.DEFAULT_NETWORK && {
90
+ 'process.env.DEFAULT_NETWORK': JSON.stringify(process.env.DEFAULT_NETWORK),
91
+ }),
85
92
  }
86
93
 
87
94
  logger.info(`Defined vars ${JSON.stringify(define, null, 2)}`)
@@ -95,6 +102,9 @@ export default async function (
95
102
  ''
96
103
  )}$)(?!.*/node_modules/.*$).*$`
97
104
 
105
+ // drop console logs if in production mode
106
+ const drop: Drop[] | undefined = mode === 'production' ? ['console', 'debugger'] : undefined
107
+
98
108
  return {
99
109
  resolve: {
100
110
  alias: aliasOptions,
@@ -114,11 +124,13 @@ export default async function (
114
124
  esbuild: {
115
125
  platform: 'node',
116
126
  target: 'node16',
127
+ drop,
128
+ legalComments: 'none',
117
129
  },
118
130
  define,
119
131
  build: {
120
132
  outDir,
121
- minify: false,
133
+ minify: isProduction,
122
134
  ssr: true,
123
135
  target: 'node16',
124
136
 
@@ -5,8 +5,11 @@ import { getLogger } from '@prosopo/common'
5
5
  import { default as noBundlePlugin } from 'vite-plugin-no-bundle'
6
6
  import VitePluginCloseAndCopy from './vite-plugin-close-and-copy.js'
7
7
  import path from 'path'
8
+ import replace from '@rollup/plugin-replace'
8
9
  import tsconfigPaths from 'vite-tsconfig-paths'
10
+
9
11
  const log = getLogger(`Info`, `vite.commonjs.config.ts`)
12
+
10
13
  export default async function (name: string, tsConfigPath: string, entry?: string): Promise<UserConfig> {
11
14
  log.info(`ViteCommonJSConfig: ${name}`)
12
15
  const projectExternal = await getExternalsFromReferences(tsConfigPath, [/dev/])
@@ -14,6 +17,11 @@ export default async function (name: string, tsConfigPath: string, entry?: strin
14
17
  return defineConfig({
15
18
  ssr: { external: allExternal },
16
19
  plugins: [
20
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
21
+ // @ts-ignore
22
+ replace({
23
+ 'esMain(import.meta)': 'require.main === module', // Replaces esMain checks with CommonJS equivalent
24
+ }),
17
25
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18
26
  // @ts-ignore
19
27
  noBundlePlugin({
@@ -6,12 +6,13 @@ import { builtinModules } from 'module'
6
6
  import { filterDependencies, getDependencies } from '../dependencies.js'
7
7
  import { getAliases } from '../polkadot/index.js'
8
8
  import { getLogger } from '@prosopo/common'
9
- import { nodeResolve } from '@rollup/plugin-node-resolve'
10
- import { viteCommonjs } from '@originjs/vite-plugin-commonjs'
9
+ import { visualizer } from 'rollup-plugin-visualizer'
11
10
  import { default as viteReact } from '@vitejs/plugin-react'
12
11
  import { wasm } from '@rollup/plugin-wasm'
13
12
  import css from 'rollup-plugin-import-css'
13
+ import nodeResolve from '@rollup/plugin-node-resolve'
14
14
  import path from 'path'
15
+ import typescript from '@rollup/plugin-typescript'
15
16
  import viteTsconfigPaths from 'vite-tsconfig-paths'
16
17
  const logger = getLogger(`Info`, `vite.config.js`)
17
18
 
@@ -41,7 +42,9 @@ export default async function (
41
42
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
42
43
  'process.env.PROTOCOL_CONTRACT_ADDRESS': JSON.stringify(process.env.PROTOCOL_CONTRACT_ADDRESS),
43
44
  'process.env.SUBSTRATE_NODE_URL': JSON.stringify(process.env.SUBSTRATE_NODE_URL),
45
+ 'process.env.REACT_APP_SUBSTRATE_ENDPOINT': JSON.stringify(process.env.SUBSTRATE_NODE_URL),
44
46
  'process.env.DEFAULT_ENVIRONMENT': JSON.stringify(process.env.DEFAULT_ENVIRONMENT),
47
+ 'process.env.DEFAULT_NETWORK': JSON.stringify(process.env.DEFAULT_NETWORK),
45
48
  'process.env.SERVER_URL': JSON.stringify(process.env.SERVER_URL),
46
49
  // only needed if bundling with a site key
47
50
  'process.env.PROSOPO_SITE_KEY': JSON.stringify(process.env.PROSOPO_SITE_KEY),
@@ -62,35 +65,40 @@ export default async function (
62
65
  ...external,
63
66
  ...optionalPeerDependencies,
64
67
  ]
65
- logger.info(`Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`)
66
- const alias = isProduction ? getAliases(dir) : []
68
+ logger.debug(`Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`)
69
+ const alias = getAliases(dir)
67
70
 
68
71
  // Required to print RegExp in console (e.g. alias keys)
69
72
  const proto = RegExp.prototype as any
70
73
  proto['toJSON'] = RegExp.prototype.toString
71
- logger.info(`aliases ${JSON.stringify(alias, null, 2)}`)
74
+ logger.debug(`aliases ${JSON.stringify(alias, null, 2)}`)
72
75
 
73
76
  // drop console logs if in production mode
74
77
  const drop: Drop[] | undefined = mode === 'production' ? ['console', 'debugger'] : undefined
75
78
 
79
+ logger.info('Bundle name', bundleName)
76
80
  return {
81
+ ssr: {
82
+ target: 'webworker',
83
+ },
77
84
  server: {
78
85
  host: '127.0.0.1',
79
86
  },
80
87
  mode: mode || 'development',
81
88
  optimizeDeps: {
82
- include: ['linked-dep', 'esm-dep > cjs-dep', 'node_modules'], //'node_modules'
83
- //exclude: ['react', 'react-dom'],
89
+ include: ['linked-dep', 'esm-dep > cjs-dep', 'node_modules'],
90
+ force: true,
84
91
  },
85
92
  esbuild: {
86
93
  platform: 'browser',
87
94
  target: ['es2020', 'chrome60', 'edge18', 'firefox60', 'node12', 'safari11'],
88
95
  drop,
96
+ legalComments: 'none',
89
97
  },
90
98
  define,
91
- // resolve: {
92
- // alias,
93
- // },
99
+ resolve: {
100
+ alias,
101
+ },
94
102
 
95
103
  build: {
96
104
  outDir: path.resolve(dir, 'dist/bundle'),
@@ -99,20 +107,31 @@ export default async function (
99
107
  lib: {
100
108
  entry: path.resolve(dir, entry),
101
109
  name: bundleName,
110
+ // sets the bundle to an Instantly Invoked Function Expression (IIFE)
102
111
  fileName: `${bundleName}.bundle.js`,
103
- // sets the bundle to an instantly invoked function expression (IIFE)
104
112
  formats: ['iife'],
105
113
  },
106
114
  modulePreload: { polyfill: true },
107
115
  commonjsOptions: {
108
116
  exclude: ['mongodb/*'],
109
117
  transformMixedEsModules: true,
118
+ strictRequires: 'debug',
110
119
  },
111
120
 
112
121
  rollupOptions: {
113
- treeshake: 'smallest',
122
+ treeshake: {
123
+ annotations: false,
124
+ propertyReadSideEffects: false,
125
+ tryCatchDeoptimization: false,
126
+ moduleSideEffects: 'no-external', //true,
127
+ preset: 'smallest',
128
+ manualPureFunctions: ['createWasmFn', 'unzlibSync', 'withWasm', 'isReady', 'initBridge', 'twox'],
129
+ unknownGlobalSideEffects: false,
130
+ },
131
+ experimentalLogSideEffects: false,
114
132
  external: allExternal,
115
133
  watch: false,
134
+
116
135
  output: {
117
136
  dir: path.resolve(dir, 'dist/bundle'),
118
137
  entryFileNames: `${bundleName}.bundle.js`,
@@ -121,19 +140,31 @@ export default async function (
121
140
  plugins: [
122
141
  css(),
123
142
  wasm(),
143
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
144
+ // @ts-ignore
124
145
  nodeResolve({
125
146
  browser: true,
126
147
  preferBuiltins: false,
127
148
  rootDir: path.resolve(dir, '../../'),
128
149
  dedupe: ['react', 'react-dom'],
150
+ modulesOnly: true,
151
+ }),
152
+ visualizer({
153
+ open: true,
154
+ template: 'treemap', //'list',
155
+ gzipSize: true,
156
+ brotliSize: true,
129
157
  }),
130
158
  // I think we can use this plugin to build all packages instead of relying on the tsc step that's
131
159
  // currently a precursor in package.json. However, it fails for the following reason:
132
160
  // https://github.com/rollup/plugins/issues/243
133
- // typescript({
134
- // tsconfig: path.resolve('./tsconfig.json'),
135
- // compilerOptions: { rootDir: path.resolve('./src') },
136
- // }),
161
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
162
+ // @ts-ignore
163
+ typescript({
164
+ tsconfig: path.resolve('./tsconfig.json'),
165
+ compilerOptions: { rootDir: path.resolve('./src') },
166
+ outDir: path.resolve(dir, 'dist/bundle'),
167
+ }),
137
168
  ],
138
169
  },
139
170
  },
@@ -142,7 +173,6 @@ export default async function (
142
173
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
143
174
  // @ts-ignore
144
175
  viteReact(),
145
- viteCommonjs(),
146
176
  // Closes the bundler and copies the bundle to the client-bundle-example project unless we're in serve
147
177
  // mode, in which case we don't want to close the bundler because it will close the server
148
178
  command !== 'serve' ? VitePluginCloseAndCopy(copyOptions) : undefined,
@@ -1,4 +1,5 @@
1
1
  import { defineConfig } from 'vitest/config'
2
+ import VitePluginCloseAndCopy from './vite-plugin-close-and-copy.js'
2
3
  import VitePluginSourcemapExclude from './vite-plugin-sourcemap-exclude.js'
3
4
 
4
5
  export default function () {
@@ -15,15 +16,24 @@ export default function () {
15
16
  },
16
17
  },
17
18
  test: {
19
+ watch: false,
20
+ //reporters: ['basic', 'hanging-process'], https://github.com/vitest-dev/vitest/issues/4415
18
21
  include: ['../../packages/*/src/**/*.test.ts', '../../contracts/*/src/**/*.test.ts'],
19
22
  exclude: ['../../demos/**/*'], // '../!packages/**/*'],
20
23
  singleThread: true,
21
- watchExclude: ['**/node_modules/**', '**/dist/**'],
24
+ watchExclude: [
25
+ '**/node_modules/**',
26
+ '**/dist/**',
27
+ '**/demos/**',
28
+ '../../packages/*/dist/**',
29
+ '../../packages/datasets-fs/src/tests/data/**',
30
+ ],
22
31
  logHeapUsage: true,
23
32
  coverage: {
24
33
  enabled: true,
25
34
  },
35
+ useAtomics: true,
26
36
  },
27
- plugins: [VitePluginSourcemapExclude({ excludeNodeModules: true })],
37
+ plugins: [VitePluginSourcemapExclude({ excludeNodeModules: true }), VitePluginCloseAndCopy()],
28
38
  })
29
39
  }