@prosopo/config 0.1.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.
Files changed (78) hide show
  1. package/dist/dependencies.d.ts +34 -0
  2. package/dist/dependencies.d.ts.map +1 -0
  3. package/dist/dependencies.js +117 -0
  4. package/dist/dependencies.js.map +1 -0
  5. package/dist/index.d.ts +5 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +5 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/polkadot/exclude.d.ts +4 -0
  10. package/dist/polkadot/exclude.d.ts.map +1 -0
  11. package/dist/polkadot/exclude.js +28 -0
  12. package/dist/polkadot/exclude.js.map +1 -0
  13. package/dist/polkadot/index.d.ts +2 -0
  14. package/dist/polkadot/index.d.ts.map +1 -0
  15. package/dist/polkadot/index.js +2 -0
  16. package/dist/polkadot/index.js.map +1 -0
  17. package/dist/polkadot/mock.d.ts +7 -0
  18. package/dist/polkadot/mock.d.ts.map +1 -0
  19. package/dist/polkadot/mock.js +6 -0
  20. package/dist/polkadot/mock.js.map +1 -0
  21. package/dist/provider/index.d.ts +2 -0
  22. package/dist/provider/index.d.ts.map +1 -0
  23. package/dist/provider/index.js +2 -0
  24. package/dist/provider/index.js.map +1 -0
  25. package/dist/provider/test.d.ts +58 -0
  26. package/dist/provider/test.d.ts.map +1 -0
  27. package/dist/provider/test.js +53 -0
  28. package/dist/provider/test.js.map +1 -0
  29. package/dist/vite/index.d.ts +7 -0
  30. package/dist/vite/index.d.ts.map +1 -0
  31. package/dist/vite/index.js +7 -0
  32. package/dist/vite/index.js.map +1 -0
  33. package/dist/vite/types.d.ts +2 -0
  34. package/dist/vite/types.d.ts.map +1 -0
  35. package/dist/vite/types.js +2 -0
  36. package/dist/vite/types.js.map +1 -0
  37. package/dist/vite/vite-plugin-close-and-copy.d.ts +12 -0
  38. package/dist/vite/vite-plugin-close-and-copy.d.ts.map +1 -0
  39. package/dist/vite/vite-plugin-close-and-copy.js +39 -0
  40. package/dist/vite/vite-plugin-close-and-copy.js.map +1 -0
  41. package/dist/vite/vite-plugin-fix-absolute-imports.d.ts +3 -0
  42. package/dist/vite/vite-plugin-fix-absolute-imports.d.ts.map +1 -0
  43. package/dist/vite/vite-plugin-fix-absolute-imports.js +23 -0
  44. package/dist/vite/vite-plugin-fix-absolute-imports.js.map +1 -0
  45. package/dist/vite/vite-plugin-sourcemap-exclude.d.ts +7 -0
  46. package/dist/vite/vite-plugin-sourcemap-exclude.d.ts.map +1 -0
  47. package/dist/vite/vite-plugin-sourcemap-exclude.js +17 -0
  48. package/dist/vite/vite-plugin-sourcemap-exclude.js.map +1 -0
  49. package/dist/vite/vite.backend.config.d.ts +3 -0
  50. package/dist/vite/vite.backend.config.d.ts.map +1 -0
  51. package/dist/vite/vite.backend.config.js +165 -0
  52. package/dist/vite/vite.backend.config.js.map +1 -0
  53. package/dist/vite/vite.frontend.config.d.ts +4 -0
  54. package/dist/vite/vite.frontend.config.d.ts.map +1 -0
  55. package/dist/vite/vite.frontend.config.js +126 -0
  56. package/dist/vite/vite.frontend.config.js.map +1 -0
  57. package/dist/vite/vite.test.config.d.ts +2 -0
  58. package/dist/vite/vite.test.config.d.ts.map +1 -0
  59. package/dist/vite/vite.test.config.js +26 -0
  60. package/dist/vite/vite.test.config.js.map +1 -0
  61. package/package.json +64 -0
  62. package/src/dependencies.ts +122 -0
  63. package/src/index.ts +4 -0
  64. package/src/polkadot/exclude.ts +30 -0
  65. package/src/polkadot/index.ts +1 -0
  66. package/src/polkadot/mock.ts +5 -0
  67. package/src/provider/index.ts +1 -0
  68. package/src/provider/test.ts +54 -0
  69. package/src/vite/index.ts +6 -0
  70. package/src/vite/types.ts +0 -0
  71. package/src/vite/vite-plugin-close-and-copy.ts +44 -0
  72. package/src/vite/vite-plugin-fix-absolute-imports.ts +24 -0
  73. package/src/vite/vite-plugin-sourcemap-exclude.ts +21 -0
  74. package/src/vite/vite.backend.config.ts +195 -0
  75. package/src/vite/vite.frontend.config.ts +147 -0
  76. package/src/vite/vite.test.config.ts +26 -0
  77. package/tsconfig.json +26 -0
  78. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,165 @@
1
+ import { default as ClosePlugin } from './vite-plugin-close-and-copy.js';
2
+ import { builtinModules } from 'module';
3
+ import { filterDependencies, getDependencies } from '../dependencies.js';
4
+ import { getLogger } from '@prosopo/common';
5
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
6
+ import { viteStaticCopy } from 'vite-plugin-static-copy';
7
+ import { wasm } from '@rollup/plugin-wasm';
8
+ import VitePluginFixAbsoluteImports from './vite-plugin-fix-absolute-imports.js';
9
+ import css from 'rollup-plugin-import-css';
10
+ import nativePlugin from 'rollup-plugin-natives';
11
+ import path from 'path';
12
+ import replace from 'vite-plugin-filter-replace';
13
+ const logger = getLogger(`Info`, `vite.backend.config.js`);
14
+ const nodeJsPolarsDeps = [
15
+ 'nodejs-polars.android-arm64.node',
16
+ 'nodejs-polars.android-arm-eabi.node',
17
+ 'nodejs-polars.win32-x64-msvc.node',
18
+ 'nodejs-polars.win32-ia32-msvc.node',
19
+ 'nodejs-polars.win32-arm64-msvc.node',
20
+ 'nodejs-polars.darwin-x64.node',
21
+ 'nodejs-polars.darwin-arm64.node',
22
+ 'nodejs-polars.freebsd-x64.node',
23
+ 'nodejs-polars.linux-x64-musl.node',
24
+ //'nodejs-polars.linux-x64-gnu.node', // - this is the only file that will be present
25
+ 'nodejs-polars.linux-arm64-musl.node',
26
+ 'nodejs-polars.linux-arm64-gnu.node',
27
+ 'nodejs-polars.linux-arm-gnueabihf.node',
28
+ ];
29
+ const aliasOptions = [
30
+ // Replace the nodejs-polars dependency with the copied .node file to avoid complaints when bundling
31
+ ...nodeJsPolarsDeps.map((dep) => ({
32
+ find: `./${dep}`,
33
+ replacement: 'nodejs-polars.linux-x64-gnu.node',
34
+ })),
35
+ ];
36
+ export default async function (packageName, packageVersion, bundleName, packageDir, entry, command, mode) {
37
+ // Get all dependencies of the current package
38
+ const { dependencies: deps, optionalPeerDependencies } = await getDependencies(packageName);
39
+ // Assuming node_modules are at the root of the workspace
40
+ const baseDir = path.resolve('../..');
41
+ const nodeModulesDir = path.resolve(baseDir, 'node_modules');
42
+ // Output directory is relative to directory of the package
43
+ const outDir = path.resolve(packageDir, 'dist/bundle');
44
+ // Get rid of any dependencies we don't want to bundle
45
+ const { external, internal } = filterDependencies(deps, ['aws', 'webpack', 'vite', 'eslint']);
46
+ // Add the node builtins (path, fs, os, etc.) to the external list
47
+ const allExternal = [
48
+ ...builtinModules,
49
+ ...builtinModules.map((m) => `node:${m}`),
50
+ ...external,
51
+ ...optionalPeerDependencies,
52
+ ];
53
+ console.log('allExternal', allExternal);
54
+ logger.info(`Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`);
55
+ const nodeJsNodeFileToCopy = path.resolve(nodeModulesDir, './nodejs-polars-linux-x64-gnu/nodejs-polars.linux-x64-gnu.node');
56
+ logger.info(`.node files to copy ${nodeJsNodeFileToCopy}`);
57
+ const define = {
58
+ 'process.env.WS_NO_BUFFER_UTIL': 'true',
59
+ 'process.env.WS_NO_UTF_8_VALIDATE': 'true',
60
+ 'process.env.PROSOPO_PACKAGE_VERSION': JSON.stringify(packageVersion),
61
+ };
62
+ logger.info(`Defined vars ${JSON.stringify(define, null, 2)}`);
63
+ return {
64
+ resolve: {
65
+ alias: aliasOptions,
66
+ },
67
+ ssr: {
68
+ noExternal: internal,
69
+ external: allExternal,
70
+ },
71
+ optimizeDeps: {
72
+ include: ['linked-dep', 'node_modules'],
73
+ esbuildOptions: {
74
+ loader: {
75
+ '.node': 'file',
76
+ },
77
+ },
78
+ },
79
+ esbuild: {
80
+ platform: 'node',
81
+ target: 'node16',
82
+ },
83
+ define,
84
+ build: {
85
+ outDir,
86
+ minify: false,
87
+ ssr: true,
88
+ target: 'node16',
89
+ lib: {
90
+ entry: path.resolve(packageDir, entry),
91
+ name: bundleName,
92
+ fileName: `${bundleName}.[name].bundle.js`,
93
+ formats: ['es'],
94
+ },
95
+ modulePreload: { polyfill: false },
96
+ commonjsOptions: {
97
+ ignore: function (id) {
98
+ // Ignore Executable and Linkable Format (ELF) files from being interpreted as CommonJS. These are
99
+ // .node files that contain WebAssembly code. They are not CommonJS modules.
100
+ return id.indexOf('nodejs-polars-linux-x64-gnu') > -1;
101
+ },
102
+ },
103
+ rollupOptions: {
104
+ treeshake: 'smallest',
105
+ external: allExternal,
106
+ watch: false,
107
+ output: {
108
+ entryFileNames: `${bundleName}.[name].bundle.js`,
109
+ },
110
+ plugins: [
111
+ // This plugin copies .node files but doesn't work for nodejs-polars. Leaving it here in case it's
112
+ // useful in the future.
113
+ nativePlugin({
114
+ // Where we want to physically put the extracted .node files
115
+ copyTo: outDir,
116
+ // Path to the same folder, relative to the output bundle js
117
+ destDir: '.',
118
+ // Generate sourcemap
119
+ sourcemap: true,
120
+ // 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.
121
+ targetEsm: true,
122
+ }),
123
+ css(),
124
+ wasm(),
125
+ nodeResolve(),
126
+ ],
127
+ },
128
+ },
129
+ plugins: [
130
+ // plugin to replace stuff like import blah from string_encoder/lib/string_encoder.js with import blah from string_encoder
131
+ VitePluginFixAbsoluteImports(),
132
+ replace.default([
133
+ // nodejs-polars is not being transformed by commonjsOptions (above) so we need to do a manual replace of
134
+ // __dirname here
135
+ {
136
+ filter: ['node_modules/nodejs-polars/bin/native-polars.js'],
137
+ replace: {
138
+ from: '__dirname',
139
+ to: "new URL(import.meta.url).pathname.split('/').slice(0,-1).join('/')",
140
+ },
141
+ },
142
+ // replace this import
143
+ {
144
+ filter: ['node_modules/nodejs-polars/bin/native-polars.js'],
145
+ replace: {
146
+ from: '__dirname',
147
+ to: "new URL(import.meta.url).pathname.split('/').slice(0,-1).join('/')",
148
+ },
149
+ },
150
+ ]),
151
+ // We need the .node files to be available to the bundle
152
+ viteStaticCopy({
153
+ targets: [
154
+ {
155
+ src: nodeJsNodeFileToCopy,
156
+ dest: outDir,
157
+ },
158
+ ],
159
+ }),
160
+ // plugin to close the bundle after build if not in serve mode
161
+ command !== 'serve' ? ClosePlugin() : undefined,
162
+ ],
163
+ };
164
+ }
165
+ //# sourceMappingURL=vite.backend.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.backend.config.js","sourceRoot":"","sources":["../../src/vite/vite.backend.config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iCAAiC,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,4BAA4B,MAAM,uCAAuC,CAAA;AAChF,OAAO,GAAG,MAAM,0BAA0B,CAAA;AAC1C,OAAO,YAAY,MAAM,uBAAuB,CAAA;AAChD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,OAAO,MAAM,4BAA4B,CAAA;AAEhD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAA;AAE1D,MAAM,gBAAgB,GAAG;IACrB,kCAAkC;IAClC,qCAAqC;IACrC,mCAAmC;IACnC,oCAAoC;IACpC,qCAAqC;IACrC,+BAA+B;IAC/B,iCAAiC;IACjC,gCAAgC;IAChC,mCAAmC;IACnC,qFAAqF;IACrF,qCAAqC;IACrC,oCAAoC;IACpC,wCAAwC;CAC3C,CAAA;AAED,MAAM,YAAY,GAAiB;IAC/B,oGAAoG;IACpG,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,G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in-close-and-copy.js';
2
+ import { UserConfig } from 'vite';
3
+ export default function (packageName: string, bundleName: string, dir: string, entry: string, command?: string, mode?: string, copyOptions?: ClosePluginOptions, tsConfigPaths?: string[]): Promise<UserConfig>;
4
+ //# sourceMappingURL=vite.frontend.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.frontend.config.d.ts","sourceRoot":"","sources":["../../src/vite/vite.frontend.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAejC,yBACI,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,kBAAkB,EAChC,aAAa,CAAC,EAAE,MAAM,EAAE,GACzB,OAAO,CAAC,UAAU,CAAC,CAyHrB"}
@@ -0,0 +1,126 @@
1
+ import { VitePluginCloseAndCopy } from './index.js';
2
+ import { builtinModules } from 'module';
3
+ import { filterDependencies, getDependencies } from '../dependencies.js';
4
+ import { getAliases } from '../polkadot/index.js';
5
+ import { getLogger } from '@prosopo/common';
6
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
7
+ import { viteCommonjs } from '@originjs/vite-plugin-commonjs';
8
+ import { default as viteReact } from '@vitejs/plugin-react';
9
+ import { wasm } from '@rollup/plugin-wasm';
10
+ import css from 'rollup-plugin-import-css';
11
+ import path from 'path';
12
+ import viteTsconfigPaths from 'vite-tsconfig-paths';
13
+ const logger = getLogger(`Info`, `vite.config.js`);
14
+ export default async function (packageName, bundleName, dir, entry, command, mode, copyOptions, tsConfigPaths) {
15
+ logger.info(`Running at ${dir} in ${mode} mode`);
16
+ const isProduction = mode === 'production';
17
+ // NODE_ENV must be wrapped in quotes. We just set it to the mode and ignore what's in the env file, otherwise the
18
+ // mode and NODE_ENV can end up out of sync (one set to development and the other set to production, which causes
19
+ // issues like this: https://github.com/hashicorp/next-mdx-remote/pull/323
20
+ process.env.NODE_ENV = `${mode}`;
21
+ logger.info(`NODE_ENV: ${process.env.NODE_ENV}`);
22
+ // Set the env vars that we want to be available in the browser
23
+ const define = {
24
+ // used to stop websockets package from breaking
25
+ 'process.env.WS_NO_BUFFER_UTIL': JSON.stringify('true'),
26
+ 'process.env.WS_NO_UTF_8_VALIDATE': JSON.stringify('true'),
27
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
28
+ 'process.env.PROTOCOL_CONTRACT_ADDRESS': JSON.stringify(process.env.PROTOCOL_CONTRACT_ADDRESS),
29
+ 'process.env.SUBSTRATE_NODE_URL': JSON.stringify(process.env.SUBSTRATE_NODE_URL),
30
+ 'process.env.DEFAULT_ENVIRONMENT': JSON.stringify(process.env.DEFAULT_ENVIRONMENT),
31
+ 'process.env.SERVER_URL': JSON.stringify(process.env.SERVER_URL),
32
+ // only needed if bundling with a site key
33
+ 'process.env.PROSOPO_SITE_KEY': JSON.stringify(process.env.PROSOPO_SITE_KEY),
34
+ };
35
+ logger.info(`Env vars: ${JSON.stringify(define, null, 4)}`);
36
+ // Get all dependencies of the current package
37
+ const { dependencies: deps, optionalPeerDependencies } = await getDependencies(packageName);
38
+ // Get rid of any dependencies we don't want to bundle
39
+ const { external, internal } = filterDependencies(deps, ['pm2', 'nodejs-polars', 'aws', 'webpack', 'vite']);
40
+ // Add the node builtins (path, fs, os, etc.) to the external list
41
+ const allExternal = [
42
+ ...builtinModules,
43
+ ...builtinModules.map((m) => `node:${m}`),
44
+ ...external,
45
+ ...optionalPeerDependencies,
46
+ ];
47
+ logger.info(`Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`);
48
+ const alias = isProduction ? getAliases(dir) : [];
49
+ // Required to print RegExp in console (e.g. alias keys)
50
+ RegExp.prototype['toJSON'] = RegExp.prototype.toString;
51
+ logger.info(`aliases ${JSON.stringify(alias, null, 2)}`);
52
+ return {
53
+ server: {
54
+ host: '127.0.0.1',
55
+ },
56
+ mode: mode || 'development',
57
+ optimizeDeps: {
58
+ include: ['linked-dep', 'esm-dep > cjs-dep', 'node_modules'], //'node_modules'
59
+ //exclude: ['react', 'react-dom'],
60
+ },
61
+ esbuild: {
62
+ platform: 'browser',
63
+ target: ['es2020', 'chrome60', 'edge18', 'firefox60', 'node12', 'safari11'],
64
+ },
65
+ define,
66
+ // resolve: {
67
+ // alias,
68
+ // },
69
+ build: {
70
+ outDir: path.resolve(dir, 'dist/bundle'),
71
+ minify: isProduction,
72
+ ssr: false,
73
+ lib: {
74
+ entry: path.resolve(dir, entry),
75
+ name: bundleName,
76
+ fileName: `${bundleName}.bundle.js`,
77
+ // sets the bundle to an instantly invoked function expression (IIFE)
78
+ formats: ['iife'],
79
+ },
80
+ modulePreload: { polyfill: true },
81
+ commonjsOptions: {
82
+ exclude: ['mongodb/*'],
83
+ transformMixedEsModules: true,
84
+ },
85
+ rollupOptions: {
86
+ treeshake: 'smallest',
87
+ external: allExternal,
88
+ watch: false,
89
+ output: {
90
+ dir: path.resolve(dir, 'dist/bundle'),
91
+ entryFileNames: `${bundleName}.bundle.js`,
92
+ },
93
+ plugins: [
94
+ css(),
95
+ wasm(),
96
+ nodeResolve({
97
+ browser: true,
98
+ preferBuiltins: false,
99
+ rootDir: path.resolve(dir, '../../'),
100
+ dedupe: ['react', 'react-dom'],
101
+ }),
102
+ // I think we can use this plugin to build all packages instead of relying on the tsc step that's
103
+ // currently a precursor in package.json. However, it fails for the following reason:
104
+ // https://github.com/rollup/plugins/issues/243
105
+ // typescript({
106
+ // tsconfig: path.resolve('./tsconfig.json'),
107
+ // compilerOptions: { rootDir: path.resolve('./src') },
108
+ // }),
109
+ ],
110
+ },
111
+ },
112
+ plugins: [
113
+ // Not sure if we need this plugin or not, it works without it
114
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
115
+ // @ts-ignore
116
+ viteReact(),
117
+ viteCommonjs(),
118
+ // Closes the bundler and copies the bundle to the client-bundle-example project unless we're in serve
119
+ // mode, in which case we don't want to close the bundler because it will close the server
120
+ command !== 'serve' ? VitePluginCloseAndCopy(copyOptions) : undefined,
121
+ // Means we can specify index.tsx instead of index.jsx in the index.html file
122
+ viteTsconfigPaths({ projects: tsConfigPaths }),
123
+ ],
124
+ };
125
+ }
126
+ //# sourceMappingURL=vite.frontend.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.frontend.config.js","sourceRoot":"","sources":["../../src/vite/vite.frontend.config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAC7D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,GAAG,MAAM,0BAA0B,CAAA;AAC1C,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,iBAAiB,MAAM,qBAAqB,CAAA;AACnD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;AAElD,MAAM,CAAC,OAAO,CAAC,KAAK,WAChB,WAAmB,EACnB,UAAkB,EAClB,GAAW,EACX,KAAa,EACb,OAAgB,EAChB,IAAa,EACb,WAAgC,EAChC,aAAwB;IAExB,MAAM,CAAC,IAAI,CAAC,cAA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AAO,CAAC,CAAC,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;YACrE,6EAA6E;YAC7E,iBAAiB,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;SACjD;KACJ,CAAA;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function (): import("vite").UserConfig;
2
+ //# sourceMappingURL=vite.test.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.test.config.d.ts","sourceRoot":"","sources":["../../src/vite/vite.test.config.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,wCAsBb"}
@@ -0,0 +1,26 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import VitePluginSourcemapExclude from './vite-plugin-sourcemap-exclude.js';
3
+ export default function () {
4
+ return defineConfig({
5
+ build: {
6
+ minify: false,
7
+ sourcemap: false,
8
+ rollupOptions: {
9
+ maxParallelFileOps: 1,
10
+ cache: false,
11
+ output: {
12
+ sourcemap: false,
13
+ },
14
+ },
15
+ },
16
+ test: {
17
+ include: ['../../packages/*/tests/**/*.test.ts'],
18
+ exclude: ['../../demos/**/*'],
19
+ minThreads: 1,
20
+ maxThreads: 1,
21
+ watchExclude: ['**/node_modules/**', '**/dist/**'],
22
+ },
23
+ plugins: [VitePluginSourcemapExclude({ excludeNodeModules: true })],
24
+ });
25
+ }
26
+ //# sourceMappingURL=vite.test.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.test.config.js","sourceRoot":"","sources":["../../src/vite/vite.test.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,0BAA0B,MAAM,oCAAoC,CAAA;AAE3E,MAAM,CAAC,OAAO;IACV,OAAO,YAAY,CAAC;QAChB,KAAK,EAAE;YACH,MAAM,EAAE,KAAK;YACb,SAAS,EAAE,KAAK;YAChB,aAAa,EAAE;gBACX,kBAAkB,EAAE,CAAC;gBACrB,KAAK,EAAE,KAAK;gBACZ,MAAM,EAAE;oBACJ,SAAS,EAAE,KAAK;iBACnB;aACJ;SACJ;QACD,IAAI,EAAE;YACF,OAAO,EAAE,CAAC,qCAAqC,CAAC;YAChD,OAAO,EAAE,CAAC,kBAAkB,CAAC;YAC7B,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,CAAC;YACb,YAAY,EAAE,CAAC,oBAAoB,EAAE,YAAY,CAAC;SACrD;QACD,OAAO,EAAE,CAAC,0BAA0B,CAAC,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;KACtE,CAAC,CAAA;AACN,CAAC"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@prosopo/config",
3
+ "version": "0.1.17",
4
+ "description": "Prosopo config library",
5
+ "main": "./dist/index.js",
6
+ "type": "module",
7
+ "types": "./dist/webpack/index.d.ts",
8
+ "scripts": {
9
+ "clean": "tsc --build --clean",
10
+ "build": "tsc --build --verbose",
11
+ "lint": "npx eslint .",
12
+ "lint:fix": "npx eslint . --fix"
13
+ },
14
+ "author": "Prosopo Limited",
15
+ "license": "Apache-2.0",
16
+ "dependencies": {
17
+ "@prosopo/common": "^0.1.17",
18
+ "@prosopo/types": "^0.1.17",
19
+ "glob": "^10.0.0"
20
+ },
21
+ "devDependencies": {
22
+ "@polkadot/dev": "^0.76.11",
23
+ "@rollup/plugin-alias": "^5.0.0",
24
+ "@rollup/plugin-babel": "^6.0.3",
25
+ "@rollup/plugin-commonjs": "^24.1.0",
26
+ "@rollup/plugin-dynamic-import-vars": "^2.0.4",
27
+ "@rollup/plugin-inject": "^5.0.3",
28
+ "@rollup/plugin-json": "^6.0.0",
29
+ "@rollup/plugin-node-resolve": "^15.1.0",
30
+ "@rollup/plugin-typescript": "^11.1.2",
31
+ "@types/react": "^18.2.7",
32
+ "@types/react-dom": "^18.2.4",
33
+ "@typescript-eslint/eslint-plugin": "^5.59.5",
34
+ "@typescript-eslint/parser": "^5.30.7",
35
+ "eslint": "^8.40.0",
36
+ "eslint-config-prettier": "^8.5.0",
37
+ "eslint-plugin-prettier": "^4.2.1",
38
+ "eslint-plugin-unused-imports": "^2.0.0",
39
+ "react": "^18.2.0",
40
+ "react-dom": "^18.2.0",
41
+ "regenerator-runtime": "^0.14.0",
42
+ "rollup-plugin-cleanup": "^3.2.1",
43
+ "tsconfig-paths": "^4.2.0",
44
+ "typescript": "^4.9.5",
45
+ "vite": "^4.4.9",
46
+ "vite-bundle-visualizer": "^0.10.0",
47
+ "vite-plugin-filter-replace": "^0.1.12",
48
+ "vite-plugin-native": "^0.2.0",
49
+ "vite-plugin-static-copy": "^0.17.0",
50
+ "vite-tsconfig-paths": "^4.2.0"
51
+ },
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/prosopo/captcha.git"
55
+ },
56
+ "bugs": {
57
+ "url": "https://github.com/prosopo/captcha/issues"
58
+ },
59
+ "homepage": "https://github.com/prosopo/captcha#readme",
60
+ "publishConfig": {
61
+ "registry": "https://registry.npmjs.org"
62
+ },
63
+ "sideEffects": false
64
+ }
@@ -0,0 +1,122 @@
1
+ import { Glob } from 'glob'
2
+ import { ProsopoEnvError, getLogger } from '@prosopo/common'
3
+ import child_process from 'child_process'
4
+ import util from 'util'
5
+ const logger = getLogger(`Info`, `config.dependencies.js`)
6
+ const exec = util.promisify(child_process.exec)
7
+
8
+ const peerDepsRegex = /UNMET\sOPTIONAL\sDEPENDENCY\s+(@*[\w-/._]+)@/
9
+ const depsRegex = /\s+(@*[\w-/._]+)@/
10
+ async function getPackageDir(packageName: string): Promise<string> {
11
+ let pkg = packageName
12
+ if (packageName && !packageName.startsWith('@prosopo/')) {
13
+ pkg = `@prosopo/${packageName}`
14
+ }
15
+ const pkgCommand = `npm list ${pkg} -ap`
16
+ logger.info(`Running command ${pkgCommand}`)
17
+ // get package directory
18
+ const { stdout: packageDir, stderr } = await exec(pkgCommand)
19
+ if (stderr) {
20
+ throw new ProsopoEnvError(new Error(stderr))
21
+ }
22
+ return packageDir.trim()
23
+ }
24
+
25
+ /**
26
+ * Get the dependencies for a package
27
+ * @param packageName
28
+ */
29
+ export async function getDependencies(
30
+ packageName?: string
31
+ ): Promise<{ dependencies: string[]; optionalPeerDependencies: string[] }> {
32
+ let cmd = 'npm ls -a'
33
+
34
+ if (packageName) {
35
+ const packageDir = await getPackageDir(packageName)
36
+ cmd = `cd ${packageDir.trim()} && ${cmd}`
37
+ logger.info(`Running command ${cmd} in ${packageDir}`)
38
+ }
39
+
40
+ const { stdout, stderr } = await exec(cmd)
41
+ if (stderr) {
42
+ throw new ProsopoEnvError(new Error(stderr))
43
+ }
44
+ const deps: string[] = []
45
+ const peerDeps: string[] = []
46
+ // for each line, check if there is an unmet optional dependency
47
+ stdout.split('\n').forEach((line) => {
48
+ if (line.includes('UNMET OPTIONAL DEPENDENCY')) {
49
+ // │ │ │ ├── UNMET OPTIONAL DEPENDENCY bufferutil@^4.0.1
50
+ const parts = line.match(peerDepsRegex)
51
+ if (parts && parts.length > 1) {
52
+ peerDeps.push(parts[1])
53
+ }
54
+ } else {
55
+ // │ │ │ ├─┬ mongodb-memory-server-core@8.15.1
56
+ const parts = line.match(depsRegex)
57
+ if (parts && parts.length > 1) {
58
+ deps.push(parts[1])
59
+ }
60
+ }
61
+ })
62
+ // dedupe and return deps and peer deps
63
+ return {
64
+ dependencies: deps.filter((x, i) => i === deps.indexOf(x)),
65
+ optionalPeerDependencies: peerDeps.filter((x, i) => i === peerDeps.indexOf(x)),
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Filter out the dependencies we don't want
71
+ * @param deps
72
+ * @param filters
73
+ */
74
+ export function filterDependencies(deps: string[], filters: string[]): { internal: string[]; external: string[] } {
75
+ const depsDeduped = deps.filter((x, i) => i === deps.indexOf(x))
76
+ const depsWithLength = depsDeduped.filter((dep) => dep.length > 0).sort()
77
+ const exclude = new RegExp(`${filters.join('|')}`)
78
+ // filter out the deps we don't want
79
+ const internal: string[] = []
80
+ const external: string[] = []
81
+ for (const dep of depsWithLength) {
82
+ if (exclude.test(dep)) {
83
+ external.push(dep)
84
+ } else {
85
+ internal.push(dep)
86
+ }
87
+ }
88
+ return { internal, external }
89
+ }
90
+
91
+ /** Takes an array of partial module directories, finds the full path, and returns an array containing the file paths
92
+ * of the files contained within the matching module directories [ filePath, filePath, ... ]
93
+ * @param startDir
94
+ * @param includePatterns
95
+ * @param excludePatterns
96
+ * @returns
97
+ * @example
98
+ * const includePatterns = ['kusama.js', 'westend.js']
99
+ * const excludePatterns = ['bytes.js']
100
+ * const startDir = path.resolve(__dirname, '../../node_modules/@polkadot')
101
+ * const files = getFilesInDirs(startDir, includePatterns, excludePatterns)
102
+ * console.log(files)
103
+ * // [ '/home/.../node_modules/@polkadot/types/interfaces/bytes/bytes.js',
104
+ * // '/home/.../node_modules/@polkadot/types/interfaces/bytes/bytes.d.ts']
105
+ * */
106
+ export function getFilesInDirs(startDir, includePatterns: string[] = [], excludePatterns: string[] = []) {
107
+ const files: string[] = []
108
+ logger.info(`getFilesInDirs: ${startDir} excluding ${includePatterns} including ${excludePatterns}`)
109
+ const ignorePatterns = excludePatterns.map((pattern) => `${startDir}/**/${pattern}`)
110
+ includePatterns.forEach((searchPattern) => {
111
+ // get matching module directories
112
+ const globPattern = `${startDir}/**/${searchPattern}${searchPattern.indexOf('.') > -1 ? '' : '/*'}`
113
+ //log.info(`globPattern: ${globPattern}`)
114
+ const globResult = new Glob(globPattern, { recursive: true, ignore: ignorePatterns }).walkSync()
115
+ //log.info(`globResult: ${globResult}`)
116
+ for (const filePath of globResult) {
117
+ files.push(filePath)
118
+ //log.info(`ignoring ${filePath}`)
119
+ }
120
+ })
121
+ return files
122
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './vite/index.js'
2
+ export * from './dependencies.js'
3
+ export * from './polkadot/index.js'
4
+ export * from './provider/index.js'
@@ -0,0 +1,30 @@
1
+ import { Alias } from 'vite'
2
+ import { getLogger } from '@prosopo/common'
3
+ import path from 'path'
4
+
5
+ const log = getLogger(`Info`, `config.polkadot.exclude.js`)
6
+ export function excludePolkadot() {
7
+ //'bytes.js'] //...interfacesToIgnore]
8
+ //const startDir = path.resolve(path.resolve(), '../../node_modules/@polkadot')
9
+ //log.info(`startDir: ${startDir}`)
10
+ //return getFilesInDirs(startDir, excludeFiles)
11
+ return ['./kusama.js', './westend.js', './cjs/bytes.js']
12
+ }
13
+
14
+ export function getAliases(dir): Alias[] {
15
+ const polkadotFilesToAlias = excludePolkadot()
16
+ const alias: Alias[] = []
17
+ // TODO Is there a way to determine this path by importing mock.js?
18
+ const mockFile = path.resolve(dir, '../config/dist/polkadot/mock.js')
19
+ polkadotFilesToAlias.forEach((file) => {
20
+ log.info(`resolving ${file} to mock.js`)
21
+ alias.push({ find: file, replacement: mockFile })
22
+ })
23
+ for (const pkg of ['api', 'api-contract', 'extension-dapp', 'types', 'util', 'util-crypto']) {
24
+ alias.push({
25
+ find: new RegExp(`/@polkadot/${pkg}$/`),
26
+ replacement: path.resolve(dir, `../../node_modules/@polkadot/${pkg}/bundle-polkadot-${pkg}.js`),
27
+ })
28
+ }
29
+ return alias
30
+ }
@@ -0,0 +1 @@
1
+ export { excludePolkadot, getAliases } from './exclude.js'
@@ -0,0 +1,5 @@
1
+ export const upgrades = []
2
+ export const versioned = []
3
+ export const statemint = []
4
+ export const shell = []
5
+ export default []
@@ -0,0 +1 @@
1
+ export { default as testConfig } from './test.js'
@@ -0,0 +1,54 @@
1
+ import { DatabaseTypes, EnvironmentTypesSchema } from '@prosopo/types'
2
+ import { getLogLevel } from '@prosopo/common'
3
+
4
+ const logLevel = getLogLevel()
5
+ export default {
6
+ logLevel,
7
+ contract: { abi: '../contract/src/abi/prosopo.json' }, // Deprecated for abiJson.
8
+ defaultEnvironment: EnvironmentTypesSchema.Values.development,
9
+ account: {
10
+ password: '',
11
+ address: '',
12
+ },
13
+ networks: {
14
+ development: {
15
+ endpoint: process.env.SUBSTRATE_NODE_URL || 'ws://localhost:9944',
16
+ contract: {
17
+ address: process.env.PROTOCOL_CONTRACT_ADDRESS || '',
18
+ name: 'prosopo',
19
+ },
20
+ accounts: ['//Alice', '//Bob', '//Charlie', '//Dave', '//Eve', '//Ferdie'],
21
+ },
22
+ },
23
+
24
+ captchas: {
25
+ solved: {
26
+ count: 1,
27
+ },
28
+ unsolved: {
29
+ count: 1,
30
+ },
31
+ },
32
+ captchaSolutions: {
33
+ requiredNumberOfSolutions: 3,
34
+ solutionWinningPercentage: 80,
35
+ captchaFilePath: './tests/mocks/data/captchas.json', // not used
36
+ captchaBlockRecency: 10,
37
+ },
38
+ database: {
39
+ development: { type: DatabaseTypes.enum.mongoMemory, endpoint: '', dbname: 'prosopo_test', authSource: '' },
40
+ },
41
+ assets: {
42
+ absolutePath: '',
43
+ basePath: '',
44
+ },
45
+ server: {
46
+ baseURL: 'http://localhost',
47
+ port: 9229,
48
+ fileServePaths: '[]',
49
+ },
50
+ batchCommit: {
51
+ interval: 1000000,
52
+ maxBatchExtrinsicPercentage: 59,
53
+ },
54
+ }