@prosopo/config 0.2.16 → 0.2.17

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.
@@ -1,224 +0,0 @@
1
- import { AliasOptions, UserConfig } from 'vite'
2
- import { default as ClosePlugin } from './vite-plugin-close-and-copy.js'
3
- import { Drop } from 'esbuild'
4
- import { builtinModules } from 'module'
5
- import { filterDependencies, getDependencies } from '../dependencies.js'
6
- import { getLogger } from '@prosopo/common'
7
- import { nodeResolve } from '@rollup/plugin-node-resolve'
8
- import { viteStaticCopy } from 'vite-plugin-static-copy'
9
- import { wasm } from '@rollup/plugin-wasm'
10
- import VitePluginFixAbsoluteImports from './vite-plugin-fix-absolute-imports.js'
11
- import css from 'rollup-plugin-import-css'
12
- import nativePlugin from 'rollup-plugin-natives'
13
- import path from 'path'
14
- import replace from 'vite-plugin-filter-replace'
15
-
16
- const logger = getLogger(`Info`, `vite.backend.config.js`)
17
-
18
- const nodeJsPolarsDeps = [
19
- 'nodejs-polars.android-arm64.node',
20
- 'nodejs-polars.android-arm-eabi.node',
21
- 'nodejs-polars.win32-x64-msvc.node',
22
- 'nodejs-polars.win32-ia32-msvc.node',
23
- 'nodejs-polars.win32-arm64-msvc.node',
24
- 'nodejs-polars.darwin-x64.node',
25
- 'nodejs-polars.darwin-arm64.node',
26
- 'nodejs-polars.freebsd-x64.node',
27
- 'nodejs-polars.linux-x64-musl.node',
28
- //'nodejs-polars.linux-x64-gnu.node', // - this is the only file that will be present
29
- 'nodejs-polars.linux-arm64-musl.node',
30
- 'nodejs-polars.linux-arm64-gnu.node',
31
- 'nodejs-polars.linux-arm-gnueabihf.node',
32
- ]
33
-
34
- const aliasOptions: AliasOptions = [
35
- // Replace the nodejs-polars dependency with the copied .node file to avoid complaints when bundling
36
- ...nodeJsPolarsDeps.map((dep) => ({
37
- find: `./${dep}`,
38
- replacement: 'nodejs-polars.linux-x64-gnu.node',
39
- })),
40
- ]
41
-
42
- export default async function (
43
- packageName: string,
44
- packageVersion: string,
45
- bundleName: string,
46
- packageDir: string,
47
- entry: string,
48
- command?: string,
49
- mode?: string
50
- ): Promise<UserConfig> {
51
- const isProduction = mode === 'production'
52
-
53
- // Get all dependencies of the current package
54
- const { dependencies: deps, optionalPeerDependencies } = await getDependencies(packageName, true)
55
-
56
- // Assuming node_modules are at the root of the workspace
57
- const baseDir = path.resolve('../..')
58
- const nodeModulesDir = path.resolve(baseDir, 'node_modules')
59
-
60
- // Output directory is relative to directory of the package
61
- const outDir = path.resolve(packageDir, 'dist/bundle')
62
-
63
- // Get rid of any dependencies we don't want to bundle
64
- const { external, internal } = filterDependencies(deps, ['aws', 'webpack', 'vite', 'eslint'])
65
-
66
- // Add the node builtins (path, fs, os, etc.) to the external list
67
- const allExternal = [
68
- ...builtinModules,
69
- ...builtinModules.map((m) => `node:${m}`),
70
- ...external,
71
- ...optionalPeerDependencies,
72
- ]
73
-
74
- logger.info(`Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`)
75
-
76
- const nodeJsNodeFileToCopy = path.resolve(
77
- nodeModulesDir,
78
- './nodejs-polars-linux-x64-gnu/nodejs-polars.linux-x64-gnu.node'
79
- )
80
- logger.info(`.node files to copy ${nodeJsNodeFileToCopy}`)
81
-
82
- const define = {
83
- 'process.env.WS_NO_BUFFER_UTIL': 'true',
84
- 'process.env.WS_NO_UTF_8_VALIDATE': 'true',
85
- 'process.env.PROSOPO_PACKAGE_VERSION': JSON.stringify(packageVersion),
86
- ...(process.env.PROSOPO_DEFAULT_ENVIRONMENT && {
87
- 'process.env.PROSOPO_DEFAULT_ENVIRONMENT': JSON.stringify(process.env.PROSOPO_DEFAULT_ENVIRONMENT),
88
- }),
89
- ...(process.env.PROSOPO_DEFAULT_NETWORK && {
90
- 'process.env.PROSOPO_DEFAULT_NETWORK': JSON.stringify(process.env.PROSOPO_DEFAULT_NETWORK),
91
- }),
92
- }
93
-
94
- logger.info(`Defined vars ${JSON.stringify(define, null, 2)}`)
95
-
96
- const entryAbsolute = path.resolve(packageDir, entry)
97
-
98
- const packageNameShort = packageName.replace('@prosopo/', '')
99
-
100
- const filterEntry = `^${baseDir}/packages/(?!${packageNameShort}/src/${entry.replace(
101
- './src/',
102
- ''
103
- )}$)(?!.*/node_modules/.*$).*$`
104
-
105
- // drop console logs if in production mode
106
- const drop: Drop[] | undefined = mode === 'production' ? ['console', 'debugger'] : undefined
107
-
108
- return {
109
- resolve: {
110
- alias: aliasOptions,
111
- },
112
- ssr: {
113
- noExternal: internal,
114
- external: allExternal,
115
- },
116
- optimizeDeps: {
117
- include: ['linked-dep', 'node_modules'],
118
- esbuildOptions: {
119
- loader: {
120
- '.node': 'file',
121
- },
122
- },
123
- },
124
- esbuild: {
125
- platform: 'node',
126
- target: 'node16',
127
- drop,
128
- legalComments: 'none',
129
- },
130
- define,
131
- build: {
132
- outDir,
133
- minify: isProduction,
134
- ssr: true,
135
- target: 'node16',
136
-
137
- lib: {
138
- entry: entryAbsolute,
139
- name: bundleName,
140
- fileName: `${bundleName}.[name].bundle.js`,
141
- formats: ['es'],
142
- },
143
- modulePreload: { polyfill: false },
144
- commonjsOptions: {
145
- ignore: function (id) {
146
- // Ignore Executable and Linkable Format (ELF) files from being interpreted as CommonJS. These are
147
- // .node files that contain WebAssembly code. They are not CommonJS modules.
148
- return id.indexOf('nodejs-polars-linux-x64-gnu') > -1
149
- },
150
- },
151
- rollupOptions: {
152
- treeshake: 'smallest',
153
- external: allExternal,
154
- watch: false,
155
- output: {
156
- entryFileNames: `${bundleName}.[name].bundle.js`,
157
- },
158
-
159
- plugins: [
160
- // This plugin copies .node files but doesn't work for nodejs-polars. Leaving it here in case it's
161
- // useful in the future.
162
- nativePlugin({
163
- // Where we want to physically put the extracted .node files
164
- copyTo: outDir,
165
-
166
- // Path to the same folder, relative to the output bundle js
167
- destDir: '.',
168
-
169
- // Generate sourcemap
170
- sourcemap: true,
171
-
172
- // 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.
173
- targetEsm: true,
174
- }),
175
- css(),
176
- wasm(),
177
- nodeResolve(),
178
- ],
179
- },
180
- },
181
- plugins: [
182
- // plugin to replace stuff like import blah from string_encoder/lib/string_encoder.js with import blah from string_encoder
183
- VitePluginFixAbsoluteImports(),
184
- replace.default([
185
- // nodejs-polars is not being transformed by commonjsOptions (above) so we need to do a manual replace of
186
- // __dirname here
187
- {
188
- filter: ['node_modules/nodejs-polars/bin/native-polars.js'],
189
- replace: {
190
- from: '__dirname',
191
- to: "new URL(import.meta.url).pathname.split('/').slice(0,-1).join('/')",
192
- },
193
- },
194
- // replace this import
195
- {
196
- filter: ['node_modules/nodejs-polars/bin/native-polars.js'],
197
- replace: {
198
- from: '__dirname',
199
- to: "new URL(import.meta.url).pathname.split('/').slice(0,-1).join('/')",
200
- },
201
- },
202
- // replace any references to main process where we are not expecting it
203
- {
204
- filter: new RegExp(filterEntry),
205
- replace: {
206
- from: 'isMain(import.meta)',
207
- to: 'false',
208
- },
209
- },
210
- ]),
211
- // We need the .node files to be available to the bundle
212
- viteStaticCopy({
213
- targets: [
214
- {
215
- src: nodeJsNodeFileToCopy,
216
- dest: outDir,
217
- },
218
- ],
219
- }),
220
- // plugin to close the bundle after build if not in serve mode
221
- command !== 'serve' ? ClosePlugin() : undefined,
222
- ],
223
- }
224
- }
@@ -1,50 +0,0 @@
1
- import { UserConfig, defineConfig } from 'vite'
2
- import { builtinModules } from 'module'
3
- import { getExternalsFromReferences } from '../dependencies.js'
4
- import { getLogger } from '@prosopo/common'
5
- import { default as noBundlePlugin } from 'vite-plugin-no-bundle'
6
- import VitePluginCloseAndCopy from './vite-plugin-close-and-copy.js'
7
- import path from 'path'
8
- import replace from '@rollup/plugin-replace'
9
- import tsconfigPaths from 'vite-tsconfig-paths'
10
-
11
- const log = getLogger(`Info`, `vite.commonjs.config.ts`)
12
-
13
- export default async function (name: string, tsConfigPath: string, entry?: string): Promise<UserConfig> {
14
- log.info(`ViteCommonJSConfig: ${name}`)
15
- const projectExternal = await getExternalsFromReferences(tsConfigPath, [/dev/])
16
- const allExternal = [...builtinModules, ...builtinModules.map((m) => `node:${m}`), ...projectExternal]
17
- return defineConfig({
18
- ssr: { external: allExternal },
19
- plugins: [
20
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
21
- // @ts-ignore
22
- replace({
23
- 'import.meta.url': 'module', // Replaces ESM checks with CommonJS equivalent
24
- }),
25
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
26
- // @ts-ignore
27
- noBundlePlugin({
28
- root: 'src',
29
- copy: '**/*.css',
30
- }),
31
- tsconfigPaths({ projects: [path.resolve('./tsconfig.cjs.json')] }),
32
- VitePluginCloseAndCopy(),
33
- ],
34
- build: {
35
- emptyOutDir: true,
36
- ssr: true,
37
- target: 'node16',
38
- outDir: 'dist/cjs',
39
- lib: {
40
- name,
41
- formats: ['cjs'],
42
- entry: entry || 'src/index.ts', // required
43
- },
44
- rollupOptions: {
45
- treeshake: false,
46
- external: allExternal,
47
- },
48
- },
49
- })
50
- }
@@ -1,182 +0,0 @@
1
- import { ClosePluginOptions } from './vite-plugin-close-and-copy.js'
2
- import { Drop } from 'esbuild'
3
- import { UserConfig } from 'vite'
4
- import { VitePluginCloseAndCopy } from './index.js'
5
- import { builtinModules } from 'module'
6
- import { filterDependencies, getDependencies } from '../dependencies.js'
7
- import { getAliases } from '../polkadot/index.js'
8
- import { getLogger } from '@prosopo/common'
9
- import { visualizer } from 'rollup-plugin-visualizer'
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 nodeResolve from '@rollup/plugin-node-resolve'
14
- import path from 'path'
15
- import typescript from '@rollup/plugin-typescript'
16
- import viteTsconfigPaths from 'vite-tsconfig-paths'
17
- const logger = getLogger(`Info`, `vite.config.js`)
18
-
19
- export default async function (
20
- packageName: string,
21
- bundleName: string,
22
- dir: string,
23
- entry: string,
24
- command?: string,
25
- mode?: string,
26
- copyOptions?: ClosePluginOptions,
27
- tsConfigPaths?: string[]
28
- ): Promise<UserConfig> {
29
- logger.info(`Running at ${dir} in ${mode} mode`)
30
- const isProduction = mode === 'production'
31
- // NODE_ENV must be wrapped in quotes. We just set it to the mode and ignore what's in the env file, otherwise the
32
- // mode and NODE_ENV can end up out of sync (one set to development and the other set to production, which causes
33
- // issues like this: https://github.com/hashicorp/next-mdx-remote/pull/323
34
- process.env.NODE_ENV = `${mode}`
35
- logger.info(`NODE_ENV: ${process.env.NODE_ENV}`)
36
-
37
- // Set the env vars that we want to be available in the browser
38
- const define = {
39
- // used to stop websockets package from breaking
40
- 'process.env.WS_NO_BUFFER_UTIL': JSON.stringify('true'),
41
- 'process.env.WS_NO_UTF_8_VALIDATE': JSON.stringify('true'),
42
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
43
- 'process.env.PROSOPO_SUBSTRATE_ENDPOINT': JSON.stringify(process.env.PROSOPO_SUBSTRATE_ENDPOINT),
44
- 'process.env.PROSOPO_DEFAULT_ENVIRONMENT': JSON.stringify(process.env.PROSOPO_DEFAULT_ENVIRONMENT),
45
- 'process.env.PROSOPO_DEFAULT_NETWORK': JSON.stringify(process.env.PROSOPO_DEFAULT_NETWORK),
46
- 'process.env.PROSOPO_SERVER_URL': JSON.stringify(process.env.PROSOPO_SERVER_URL),
47
- 'process.env.PROSOPO_CONTRACT_ADDRESS': JSON.stringify(process.env.PROSOPO_CONTRACT_ADDRESS),
48
- // only needed if bundling with a site key
49
- 'process.env.PROSOPO_SITE_KEY': JSON.stringify(process.env.PROSOPO_SITE_KEY),
50
- }
51
-
52
- logger.info(`Env vars: ${JSON.stringify(define, null, 4)}`)
53
-
54
- // Get all dependencies of the current package
55
- const { dependencies: deps, optionalPeerDependencies } = await getDependencies(packageName, isProduction)
56
-
57
- // Get rid of any dependencies we don't want to bundle
58
- const { external, internal } = filterDependencies(deps, ['pm2', 'nodejs-polars', 'aws', 'webpack', 'vite'])
59
-
60
- // Add the node builtins (path, fs, os, etc.) to the external list
61
- const allExternal = [
62
- ...builtinModules,
63
- ...builtinModules.map((m) => `node:${m}`),
64
- ...external,
65
- ...optionalPeerDependencies,
66
- ]
67
- logger.debug(`Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`)
68
- const alias = getAliases(dir)
69
-
70
- // Required to print RegExp in console (e.g. alias keys)
71
- const proto = RegExp.prototype as any
72
- proto['toJSON'] = RegExp.prototype.toString
73
- logger.debug(`aliases ${JSON.stringify(alias, null, 2)}`)
74
-
75
- // drop console logs if in production mode
76
- const drop: Drop[] | undefined = mode === 'production' ? ['console', 'debugger'] : undefined
77
-
78
- logger.info('Bundle name', bundleName)
79
- return {
80
- ssr: {
81
- target: 'webworker',
82
- },
83
- server: {
84
- host: '127.0.0.1',
85
- },
86
- mode: mode || 'development',
87
- optimizeDeps: {
88
- include: ['linked-dep', 'esm-dep > cjs-dep', 'node_modules'],
89
- force: true,
90
- },
91
- esbuild: {
92
- platform: 'browser',
93
- target: ['es2020', 'chrome60', 'edge18', 'firefox60', 'node12', 'safari11'],
94
- drop,
95
- legalComments: 'none',
96
- },
97
- define,
98
- resolve: {
99
- alias,
100
- },
101
-
102
- build: {
103
- outDir: path.resolve(dir, 'dist/bundle'),
104
- minify: isProduction,
105
- ssr: false,
106
- lib: {
107
- entry: path.resolve(dir, entry),
108
- name: bundleName,
109
- // sets the bundle to an Instantly Invoked Function Expression (IIFE)
110
- fileName: `${bundleName}.bundle.js`,
111
- formats: ['iife'],
112
- },
113
- modulePreload: { polyfill: true },
114
- commonjsOptions: {
115
- exclude: ['mongodb/*'],
116
- transformMixedEsModules: true,
117
- strictRequires: 'debug',
118
- },
119
-
120
- rollupOptions: {
121
- treeshake: {
122
- annotations: false,
123
- propertyReadSideEffects: false,
124
- tryCatchDeoptimization: false,
125
- moduleSideEffects: 'no-external', //true,
126
- preset: 'smallest',
127
- manualPureFunctions: ['createWasmFn', 'unzlibSync', 'withWasm', 'isReady', 'initBridge', 'twox'],
128
- unknownGlobalSideEffects: false,
129
- },
130
- experimentalLogSideEffects: false,
131
- external: allExternal,
132
- watch: false,
133
-
134
- output: {
135
- dir: path.resolve(dir, 'dist/bundle'),
136
- entryFileNames: `${bundleName}.bundle.js`,
137
- },
138
-
139
- plugins: [
140
- css(),
141
- wasm(),
142
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
143
- // @ts-ignore
144
- nodeResolve({
145
- browser: true,
146
- preferBuiltins: false,
147
- rootDir: path.resolve(dir, '../../'),
148
- dedupe: ['react', 'react-dom'],
149
- modulesOnly: true,
150
- }),
151
- visualizer({
152
- open: true,
153
- template: 'treemap', //'list',
154
- gzipSize: true,
155
- brotliSize: true,
156
- }),
157
- // I think we can use this plugin to build all packages instead of relying on the tsc step that's
158
- // currently a precursor in package.json. However, it fails for the following reason:
159
- // https://github.com/rollup/plugins/issues/243
160
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
161
- // @ts-ignore
162
- typescript({
163
- tsconfig: path.resolve('./tsconfig.json'),
164
- compilerOptions: { rootDir: path.resolve('./src') },
165
- outDir: path.resolve(dir, 'dist/bundle'),
166
- }),
167
- ],
168
- },
169
- },
170
- plugins: [
171
- // Not sure if we need this plugin or not, it works without it
172
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
173
- // @ts-ignore
174
- viteReact(),
175
- // Closes the bundler and copies the bundle to the client-bundle-example project unless we're in serve
176
- // mode, in which case we don't want to close the bundler because it will close the server
177
- command !== 'serve' ? VitePluginCloseAndCopy(copyOptions) : undefined,
178
- // Means we can specify index.tsx instead of index.jsx in the index.html file
179
- viteTsconfigPaths({ projects: tsConfigPaths }),
180
- ],
181
- }
182
- }
@@ -1,39 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
- import VitePluginCloseAndCopy from './vite-plugin-close-and-copy.js'
3
- import VitePluginSourcemapExclude from './vite-plugin-sourcemap-exclude.js'
4
-
5
- export default function () {
6
- return defineConfig({
7
- build: {
8
- minify: false,
9
- sourcemap: false,
10
- rollupOptions: {
11
- maxParallelFileOps: 1,
12
- cache: false,
13
- output: {
14
- sourcemap: false,
15
- },
16
- },
17
- },
18
- test: {
19
- watch: false,
20
- //reporters: ['basic', 'hanging-process'], https://github.com/vitest-dev/vitest/issues/4415
21
- include: ['../../packages/*/src/**/*.test.ts', '../../contracts/*/src/**/*.test.ts'],
22
- exclude: ['../../demos/**/*'], // '../!packages/**/*'],
23
- singleThread: true,
24
- watchExclude: [
25
- '**/node_modules/**',
26
- '**/dist/**',
27
- '**/demos/**',
28
- '../../packages/*/dist/**',
29
- '../../packages/datasets-fs/src/tests/data/**',
30
- ],
31
- logHeapUsage: true,
32
- coverage: {
33
- enabled: true,
34
- },
35
- useAtomics: true,
36
- },
37
- plugins: [VitePluginSourcemapExclude({ excludeNodeModules: true }), VitePluginCloseAndCopy()],
38
- })
39
- }
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.esm.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- "types": ["vite/client"]
7
- },
8
- "include": ["./src/**/*.ts", "./src/**/*.d.ts", "./src/**/*.tsx"],
9
- "references": [
10
- {
11
- "path": "../../packages/common"
12
- },
13
- {
14
- "path": "../../packages/types"
15
- }
16
- ]
17
- }