@prosopo/config 0.1.17 → 0.1.18

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 (78) hide show
  1. package/package.json +7 -4
  2. package/dist/dependencies.d.ts +0 -34
  3. package/dist/dependencies.d.ts.map +0 -1
  4. package/dist/dependencies.js +0 -117
  5. package/dist/dependencies.js.map +0 -1
  6. package/dist/index.d.ts +0 -5
  7. package/dist/index.d.ts.map +0 -1
  8. package/dist/index.js +0 -5
  9. package/dist/index.js.map +0 -1
  10. package/dist/polkadot/exclude.d.ts +0 -4
  11. package/dist/polkadot/exclude.d.ts.map +0 -1
  12. package/dist/polkadot/exclude.js +0 -28
  13. package/dist/polkadot/exclude.js.map +0 -1
  14. package/dist/polkadot/index.d.ts +0 -2
  15. package/dist/polkadot/index.d.ts.map +0 -1
  16. package/dist/polkadot/index.js +0 -2
  17. package/dist/polkadot/index.js.map +0 -1
  18. package/dist/polkadot/mock.d.ts +0 -7
  19. package/dist/polkadot/mock.d.ts.map +0 -1
  20. package/dist/polkadot/mock.js +0 -6
  21. package/dist/polkadot/mock.js.map +0 -1
  22. package/dist/provider/index.d.ts +0 -2
  23. package/dist/provider/index.d.ts.map +0 -1
  24. package/dist/provider/index.js +0 -2
  25. package/dist/provider/index.js.map +0 -1
  26. package/dist/provider/test.d.ts +0 -58
  27. package/dist/provider/test.d.ts.map +0 -1
  28. package/dist/provider/test.js +0 -53
  29. package/dist/provider/test.js.map +0 -1
  30. package/dist/vite/index.d.ts +0 -7
  31. package/dist/vite/index.d.ts.map +0 -1
  32. package/dist/vite/index.js +0 -7
  33. package/dist/vite/index.js.map +0 -1
  34. package/dist/vite/types.d.ts +0 -2
  35. package/dist/vite/types.d.ts.map +0 -1
  36. package/dist/vite/types.js +0 -2
  37. package/dist/vite/types.js.map +0 -1
  38. package/dist/vite/vite-plugin-close-and-copy.d.ts +0 -12
  39. package/dist/vite/vite-plugin-close-and-copy.d.ts.map +0 -1
  40. package/dist/vite/vite-plugin-close-and-copy.js +0 -39
  41. package/dist/vite/vite-plugin-close-and-copy.js.map +0 -1
  42. package/dist/vite/vite-plugin-fix-absolute-imports.d.ts +0 -3
  43. package/dist/vite/vite-plugin-fix-absolute-imports.d.ts.map +0 -1
  44. package/dist/vite/vite-plugin-fix-absolute-imports.js +0 -23
  45. package/dist/vite/vite-plugin-fix-absolute-imports.js.map +0 -1
  46. package/dist/vite/vite-plugin-sourcemap-exclude.d.ts +0 -7
  47. package/dist/vite/vite-plugin-sourcemap-exclude.d.ts.map +0 -1
  48. package/dist/vite/vite-plugin-sourcemap-exclude.js +0 -17
  49. package/dist/vite/vite-plugin-sourcemap-exclude.js.map +0 -1
  50. package/dist/vite/vite.backend.config.d.ts +0 -3
  51. package/dist/vite/vite.backend.config.d.ts.map +0 -1
  52. package/dist/vite/vite.backend.config.js +0 -165
  53. package/dist/vite/vite.backend.config.js.map +0 -1
  54. package/dist/vite/vite.frontend.config.d.ts +0 -4
  55. package/dist/vite/vite.frontend.config.d.ts.map +0 -1
  56. package/dist/vite/vite.frontend.config.js +0 -126
  57. package/dist/vite/vite.frontend.config.js.map +0 -1
  58. package/dist/vite/vite.test.config.d.ts +0 -2
  59. package/dist/vite/vite.test.config.d.ts.map +0 -1
  60. package/dist/vite/vite.test.config.js +0 -26
  61. package/dist/vite/vite.test.config.js.map +0 -1
  62. package/src/dependencies.ts +0 -122
  63. package/src/index.ts +0 -4
  64. package/src/polkadot/exclude.ts +0 -30
  65. package/src/polkadot/index.ts +0 -1
  66. package/src/polkadot/mock.ts +0 -5
  67. package/src/provider/index.ts +0 -1
  68. package/src/provider/test.ts +0 -54
  69. package/src/vite/index.ts +0 -6
  70. package/src/vite/types.ts +0 -0
  71. package/src/vite/vite-plugin-close-and-copy.ts +0 -44
  72. package/src/vite/vite-plugin-fix-absolute-imports.ts +0 -24
  73. package/src/vite/vite-plugin-sourcemap-exclude.ts +0 -21
  74. package/src/vite/vite.backend.config.ts +0 -195
  75. package/src/vite/vite.frontend.config.ts +0 -147
  76. package/src/vite/vite.test.config.ts +0 -26
  77. package/tsconfig.json +0 -26
  78. package/tsconfig.tsbuildinfo +0 -1
@@ -1,24 +0,0 @@
1
- import { builtinModules } from 'module'
2
- import type { Plugin } from 'vite'
3
-
4
- export default function VitePluginFixAbsoluteImports(): Plugin {
5
- return {
6
- name: 'fix-absolute-imports',
7
- transform(code: string, id: string) {
8
- for (const module of builtinModules) {
9
- const moduleImportRegex = new RegExp(`from "(${module}(/.*)*/.*.js)";`, 'g')
10
- // if matches, replace match with _module
11
- const matches = code.match(moduleImportRegex)
12
- if (matches) {
13
- for (const match of matches) {
14
- code = code.replace(match, `from "${module}";`)
15
- }
16
- }
17
- }
18
- return {
19
- code,
20
- }
21
- },
22
- enforce: 'post',
23
- }
24
- }
@@ -1,21 +0,0 @@
1
- import type { Plugin } from 'vite'
2
-
3
- interface SourcemapExclude {
4
- excludeNodeModules?: boolean
5
- }
6
- // Taken from https://github.com/vitejs/vite/issues/2433#issuecomment-1487472995 to prevent memory leaks
7
- export default function VitePluginSourcemapExclude(opts?: SourcemapExclude): Plugin {
8
- return {
9
- name: 'sourcemap-exclude',
10
- transform(code: string, id: string) {
11
- if (opts?.excludeNodeModules && id.includes('node_modules')) {
12
- return {
13
- code,
14
- // https://github.com/rollup/rollup/blob/master/docs/plugin-development/index.md#source-code-transformations
15
- map: { mappings: '' },
16
- }
17
- }
18
- return
19
- },
20
- }
21
- }
@@ -1,195 +0,0 @@
1
- import { AliasOptions, UserConfig } from 'vite'
2
- import { default as ClosePlugin } from './vite-plugin-close-and-copy.js'
3
- import { builtinModules } from 'module'
4
- import { filterDependencies, getDependencies } from '../dependencies.js'
5
- import { getLogger } from '@prosopo/common'
6
- import { nodeResolve } from '@rollup/plugin-node-resolve'
7
- import { viteStaticCopy } from 'vite-plugin-static-copy'
8
- import { wasm } from '@rollup/plugin-wasm'
9
- import VitePluginFixAbsoluteImports from './vite-plugin-fix-absolute-imports.js'
10
- import css from 'rollup-plugin-import-css'
11
- import nativePlugin from 'rollup-plugin-natives'
12
- import path from 'path'
13
- import replace from 'vite-plugin-filter-replace'
14
-
15
- const logger = getLogger(`Info`, `vite.backend.config.js`)
16
-
17
- const nodeJsPolarsDeps = [
18
- 'nodejs-polars.android-arm64.node',
19
- 'nodejs-polars.android-arm-eabi.node',
20
- 'nodejs-polars.win32-x64-msvc.node',
21
- 'nodejs-polars.win32-ia32-msvc.node',
22
- 'nodejs-polars.win32-arm64-msvc.node',
23
- 'nodejs-polars.darwin-x64.node',
24
- 'nodejs-polars.darwin-arm64.node',
25
- 'nodejs-polars.freebsd-x64.node',
26
- 'nodejs-polars.linux-x64-musl.node',
27
- //'nodejs-polars.linux-x64-gnu.node', // - this is the only file that will be present
28
- 'nodejs-polars.linux-arm64-musl.node',
29
- 'nodejs-polars.linux-arm64-gnu.node',
30
- 'nodejs-polars.linux-arm-gnueabihf.node',
31
- ]
32
-
33
- const aliasOptions: AliasOptions = [
34
- // Replace the nodejs-polars dependency with the copied .node file to avoid complaints when bundling
35
- ...nodeJsPolarsDeps.map((dep) => ({
36
- find: `./${dep}`,
37
- replacement: 'nodejs-polars.linux-x64-gnu.node',
38
- })),
39
- ]
40
-
41
- export default async function (
42
- packageName: string,
43
- packageVersion: string,
44
- bundleName: string,
45
- packageDir: string,
46
- entry: string,
47
- command?: string,
48
- mode?: string
49
- ): Promise<UserConfig> {
50
- // Get all dependencies of the current package
51
- const { dependencies: deps, optionalPeerDependencies } = await getDependencies(packageName)
52
-
53
- // Assuming node_modules are at the root of the workspace
54
- const baseDir = path.resolve('../..')
55
- const nodeModulesDir = path.resolve(baseDir, 'node_modules')
56
-
57
- // Output directory is relative to directory of the package
58
- const outDir = path.resolve(packageDir, 'dist/bundle')
59
-
60
- // Get rid of any dependencies we don't want to bundle
61
- const { external, internal } = filterDependencies(deps, ['aws', 'webpack', 'vite', 'eslint'])
62
-
63
- // Add the node builtins (path, fs, os, etc.) to the external list
64
- const allExternal = [
65
- ...builtinModules,
66
- ...builtinModules.map((m) => `node:${m}`),
67
- ...external,
68
- ...optionalPeerDependencies,
69
- ]
70
-
71
- console.log('allExternal', allExternal)
72
-
73
- logger.info(`Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`)
74
-
75
- const nodeJsNodeFileToCopy = path.resolve(
76
- nodeModulesDir,
77
- './nodejs-polars-linux-x64-gnu/nodejs-polars.linux-x64-gnu.node'
78
- )
79
- logger.info(`.node files to copy ${nodeJsNodeFileToCopy}`)
80
-
81
- const define = {
82
- 'process.env.WS_NO_BUFFER_UTIL': 'true',
83
- 'process.env.WS_NO_UTF_8_VALIDATE': 'true',
84
- 'process.env.PROSOPO_PACKAGE_VERSION': JSON.stringify(packageVersion),
85
- }
86
-
87
- logger.info(`Defined vars ${JSON.stringify(define, null, 2)}`)
88
-
89
- return {
90
- resolve: {
91
- alias: aliasOptions,
92
- },
93
- ssr: {
94
- noExternal: internal,
95
- external: allExternal,
96
- },
97
- optimizeDeps: {
98
- include: ['linked-dep', 'node_modules'],
99
- esbuildOptions: {
100
- loader: {
101
- '.node': 'file',
102
- },
103
- },
104
- },
105
- esbuild: {
106
- platform: 'node',
107
- target: 'node16',
108
- },
109
- define,
110
- build: {
111
- outDir,
112
- minify: false,
113
- ssr: true,
114
- target: 'node16',
115
-
116
- lib: {
117
- entry: path.resolve(packageDir, entry),
118
- name: bundleName,
119
- fileName: `${bundleName}.[name].bundle.js`,
120
- formats: ['es'],
121
- },
122
- modulePreload: { polyfill: false },
123
- commonjsOptions: {
124
- ignore: function (id) {
125
- // Ignore Executable and Linkable Format (ELF) files from being interpreted as CommonJS. These are
126
- // .node files that contain WebAssembly code. They are not CommonJS modules.
127
- return id.indexOf('nodejs-polars-linux-x64-gnu') > -1
128
- },
129
- },
130
- rollupOptions: {
131
- treeshake: 'smallest',
132
- external: allExternal,
133
- watch: false,
134
- output: {
135
- entryFileNames: `${bundleName}.[name].bundle.js`,
136
- },
137
-
138
- plugins: [
139
- // This plugin copies .node files but doesn't work for nodejs-polars. Leaving it here in case it's
140
- // useful in the future.
141
- nativePlugin({
142
- // Where we want to physically put the extracted .node files
143
- copyTo: outDir,
144
-
145
- // Path to the same folder, relative to the output bundle js
146
- destDir: '.',
147
-
148
- // Generate sourcemap
149
- sourcemap: true,
150
-
151
- // If the target is ESM, so we can't use `require` (and .node is not supported in `import` anyway), we will need to use `createRequire` instead.
152
- targetEsm: true,
153
- }),
154
- css(),
155
- wasm(),
156
- nodeResolve(),
157
- ],
158
- },
159
- },
160
- plugins: [
161
- // plugin to replace stuff like import blah from string_encoder/lib/string_encoder.js with import blah from string_encoder
162
- VitePluginFixAbsoluteImports(),
163
- replace.default([
164
- // nodejs-polars is not being transformed by commonjsOptions (above) so we need to do a manual replace of
165
- // __dirname here
166
- {
167
- filter: ['node_modules/nodejs-polars/bin/native-polars.js'],
168
- replace: {
169
- from: '__dirname',
170
- to: "new URL(import.meta.url).pathname.split('/').slice(0,-1).join('/')",
171
- },
172
- },
173
- // replace this import
174
- {
175
- filter: ['node_modules/nodejs-polars/bin/native-polars.js'],
176
- replace: {
177
- from: '__dirname',
178
- to: "new URL(import.meta.url).pathname.split('/').slice(0,-1).join('/')",
179
- },
180
- },
181
- ]),
182
- // We need the .node files to be available to the bundle
183
- viteStaticCopy({
184
- targets: [
185
- {
186
- src: nodeJsNodeFileToCopy,
187
- dest: outDir,
188
- },
189
- ],
190
- }),
191
- // plugin to close the bundle after build if not in serve mode
192
- command !== 'serve' ? ClosePlugin() : undefined,
193
- ],
194
- }
195
- }
@@ -1,147 +0,0 @@
1
- import { ClosePluginOptions } from './vite-plugin-close-and-copy.js'
2
- import { UserConfig } from 'vite'
3
- import { VitePluginCloseAndCopy } from './index.js'
4
- import { builtinModules } from 'module'
5
- import { filterDependencies, getDependencies } from '../dependencies.js'
6
- import { getAliases } from '../polkadot/index.js'
7
- import { getLogger } from '@prosopo/common'
8
- import { nodeResolve } from '@rollup/plugin-node-resolve'
9
- import { viteCommonjs } from '@originjs/vite-plugin-commonjs'
10
- import { default as viteReact } from '@vitejs/plugin-react'
11
- import { wasm } from '@rollup/plugin-wasm'
12
- import css from 'rollup-plugin-import-css'
13
- import path from 'path'
14
- import viteTsconfigPaths from 'vite-tsconfig-paths'
15
- const logger = getLogger(`Info`, `vite.config.js`)
16
-
17
- export default async function (
18
- packageName: string,
19
- bundleName: string,
20
- dir: string,
21
- entry: string,
22
- command?: string,
23
- mode?: string,
24
- copyOptions?: ClosePluginOptions,
25
- tsConfigPaths?: string[]
26
- ): Promise<UserConfig> {
27
- logger.info(`Running at ${dir} in ${mode} mode`)
28
- const isProduction = mode === 'production'
29
- // NODE_ENV must be wrapped in quotes. We just set it to the mode and ignore what's in the env file, otherwise the
30
- // mode and NODE_ENV can end up out of sync (one set to development and the other set to production, which causes
31
- // issues like this: https://github.com/hashicorp/next-mdx-remote/pull/323
32
- process.env.NODE_ENV = `${mode}`
33
- logger.info(`NODE_ENV: ${process.env.NODE_ENV}`)
34
-
35
- // Set the env vars that we want to be available in the browser
36
- const define = {
37
- // used to stop websockets package from breaking
38
- 'process.env.WS_NO_BUFFER_UTIL': JSON.stringify('true'),
39
- 'process.env.WS_NO_UTF_8_VALIDATE': JSON.stringify('true'),
40
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
41
- 'process.env.PROTOCOL_CONTRACT_ADDRESS': JSON.stringify(process.env.PROTOCOL_CONTRACT_ADDRESS),
42
- 'process.env.SUBSTRATE_NODE_URL': JSON.stringify(process.env.SUBSTRATE_NODE_URL),
43
- 'process.env.DEFAULT_ENVIRONMENT': JSON.stringify(process.env.DEFAULT_ENVIRONMENT),
44
- 'process.env.SERVER_URL': JSON.stringify(process.env.SERVER_URL),
45
- // only needed if bundling with a site key
46
- 'process.env.PROSOPO_SITE_KEY': JSON.stringify(process.env.PROSOPO_SITE_KEY),
47
- }
48
-
49
- logger.info(`Env vars: ${JSON.stringify(define, null, 4)}`)
50
-
51
- // Get all dependencies of the current package
52
- const { dependencies: deps, optionalPeerDependencies } = await getDependencies(packageName)
53
-
54
- // Get rid of any dependencies we don't want to bundle
55
- const { external, internal } = filterDependencies(deps, ['pm2', 'nodejs-polars', 'aws', 'webpack', 'vite'])
56
-
57
- // Add the node builtins (path, fs, os, etc.) to the external list
58
- const allExternal = [
59
- ...builtinModules,
60
- ...builtinModules.map((m) => `node:${m}`),
61
- ...external,
62
- ...optionalPeerDependencies,
63
- ]
64
- logger.info(`Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`)
65
- const alias = isProduction ? getAliases(dir) : []
66
-
67
- // Required to print RegExp in console (e.g. alias keys)
68
- RegExp.prototype['toJSON'] = RegExp.prototype.toString
69
- logger.info(`aliases ${JSON.stringify(alias, null, 2)}`)
70
-
71
- return {
72
- server: {
73
- host: '127.0.0.1',
74
- },
75
- mode: mode || 'development',
76
- optimizeDeps: {
77
- include: ['linked-dep', 'esm-dep > cjs-dep', 'node_modules'], //'node_modules'
78
- //exclude: ['react', 'react-dom'],
79
- },
80
- esbuild: {
81
- platform: 'browser',
82
- target: ['es2020', 'chrome60', 'edge18', 'firefox60', 'node12', 'safari11'],
83
- },
84
- define,
85
- // resolve: {
86
- // alias,
87
- // },
88
-
89
- build: {
90
- outDir: path.resolve(dir, 'dist/bundle'),
91
- minify: isProduction,
92
- ssr: false,
93
- lib: {
94
- entry: path.resolve(dir, entry),
95
- name: bundleName,
96
- fileName: `${bundleName}.bundle.js`,
97
- // sets the bundle to an instantly invoked function expression (IIFE)
98
- formats: ['iife'],
99
- },
100
- modulePreload: { polyfill: true },
101
- commonjsOptions: {
102
- exclude: ['mongodb/*'],
103
- transformMixedEsModules: true,
104
- },
105
-
106
- rollupOptions: {
107
- treeshake: 'smallest',
108
- external: allExternal,
109
- watch: false,
110
- output: {
111
- dir: path.resolve(dir, 'dist/bundle'),
112
- entryFileNames: `${bundleName}.bundle.js`,
113
- },
114
-
115
- plugins: [
116
- css(),
117
- wasm(),
118
- nodeResolve({
119
- browser: true,
120
- preferBuiltins: false,
121
- rootDir: path.resolve(dir, '../../'),
122
- dedupe: ['react', 'react-dom'],
123
- }),
124
- // I think we can use this plugin to build all packages instead of relying on the tsc step that's
125
- // currently a precursor in package.json. However, it fails for the following reason:
126
- // https://github.com/rollup/plugins/issues/243
127
- // typescript({
128
- // tsconfig: path.resolve('./tsconfig.json'),
129
- // compilerOptions: { rootDir: path.resolve('./src') },
130
- // }),
131
- ],
132
- },
133
- },
134
- plugins: [
135
- // Not sure if we need this plugin or not, it works without it
136
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
137
- // @ts-ignore
138
- viteReact(),
139
- viteCommonjs(),
140
- // Closes the bundler and copies the bundle to the client-bundle-example project unless we're in serve
141
- // mode, in which case we don't want to close the bundler because it will close the server
142
- command !== 'serve' ? VitePluginCloseAndCopy(copyOptions) : undefined,
143
- // Means we can specify index.tsx instead of index.jsx in the index.html file
144
- viteTsconfigPaths({ projects: tsConfigPaths }),
145
- ],
146
- }
147
- }
@@ -1,26 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
- import VitePluginSourcemapExclude from './vite-plugin-sourcemap-exclude.js'
3
-
4
- export default function () {
5
- return defineConfig({
6
- build: {
7
- minify: false,
8
- sourcemap: false,
9
- rollupOptions: {
10
- maxParallelFileOps: 1,
11
- cache: false,
12
- output: {
13
- sourcemap: false,
14
- },
15
- },
16
- },
17
- test: {
18
- include: ['../../packages/*/tests/**/*.test.ts'],
19
- exclude: ['../../demos/**/*'], // '../!packages/**/*'],
20
- minThreads: 1,
21
- maxThreads: 1,
22
- watchExclude: ['**/node_modules/**', '**/dist/**'],
23
- },
24
- plugins: [VitePluginSourcemapExclude({ excludeNodeModules: true })],
25
- })
26
- }
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.build.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- "module": "esnext",
7
- "target": "esnext",
8
- "lib": [
9
- "es6",
10
- "dom"
11
- ],
12
- "jsx": "react-jsx",
13
- "types": ["vite/client"]
14
- },
15
- "include": [
16
- "src/**/*", "./env.d.ts"
17
- ],
18
- "references": [
19
- {
20
- "path": "../../packages/common"
21
- },
22
- {
23
- "path": "../../packages/types"
24
- }
25
- ]
26
- }