Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix windows CI build #2208

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
echo "version=$(node --version)" >> $GITHUB_OUTPUT

- name: Install node-pre-gyp
if: matrix.os != 'windows-latest'
run: |
npm install node-pre-gyp --prefer-offline --no-audit --progress=false

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ tsconfig.tsbuildinfo
.nyc_output

tx
.node-version
1 change: 1 addition & 0 deletions __mocks__/file-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "test-file-stub"
1 change: 1 addition & 0 deletions __mocks__/style-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
9 changes: 6 additions & 3 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

module.exports = {
presets: ['@babel/preset-react']
}
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
'@babel/preset-react'
],
};
13 changes: 13 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { build } from "esbuild";
import inlineImage from "esbuild-plugin-inline-image";

build({
entryPoints: ["./src/index.js"],
outfile: "./dist/.js",
minify: true,
bundle: true,
loader: {
".js": "jsx",
},
plugins: [inlineImage()],
}).catch(() => process.exit(1));
79 changes: 79 additions & 0 deletions build2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// import { analyzeMetafile, build, serve } from 'esbuild';
import { createServer, request, ServerResponse, IncomingMessage } from 'http';
import { relative } from 'path';
import esbuildPkg from 'esbuild';
const { analyzeMetafile, build, serve } = esbuildPkg;
// import { spawn } from 'child_process'

const clients = [];
/**
* @type {Map<string, string>}
*/
const contentMap = new Map();

const rebuild = (error, result) => {
contentMap.clear();
for (const content of result.outputFiles) {
contentMap.set(relative(".", content.path), content.text);
}
clients.forEach((res) => res.write('data: update\n\n'))
clients.length = 0
analyzeMetafile(result.metafile)
.then((text) => {
console.log(text)
console.log(error ? error : `Rebuilt at ${new Date().toLocaleString()}`)
});
}

build({
entryPoints: ['./src/index.ts'],
bundle: true,
outfile: 'bundle.js',
write: false,
incremental: true,
metafile: true,
banner: { js: ' (() => new EventSource("/esbuild").onmessage = () => location.reload())();' },
watch: {
onRebuild(error, result) {
rebuild(error, result)
},
},
})
.then(result => rebuild(null, result))
.catch(() => process.exit(1))

serve({ servedir: './' }, {}).then(() => {
createServer((req, res) => {
const { url, method, headers } = req;
const isDir = url.endsWith('/') || url.endsWith('\\');
const relativeUrl = relative("/", url);
if (req.url === '/esbuild') {
return clients.push(
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
Connection: 'keep-alive',
})
)
} else if (contentMap.has(relativeUrl)) {
res.write(contentMap.get(relativeUrl));
res.end();
return;
}
const readPath = `${relativeUrl}${isDir ? '/' : ''}`;
console.log(`Reading: ${readPath}`);
req.pipe(
request({ hostname: '0.0.0.0', port: 8000, path: `/${readPath}`, method, headers }, (prxRes) => {
res.writeHead(prxRes.statusCode || 0, prxRes.headers)
prxRes.pipe(res, { end: true })
}),
{ end: true }
)
}).listen(3000)

/* setTimeout(() => {
const op = { darwin: ['open'], linux: ['xdg-open'], win32: ['cmd', '/c', 'start'] }
const ptf = process.platform
if (clients.length === 0) spawn(op[ptf][0], [...[op[ptf].slice(1)], `http://localhost:3000`])
}, 1000) //open the default browser only if it is not opened yet */
})
126 changes: 63 additions & 63 deletions config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @see https://github.com/facebook/create-react-app/issues/11756#issuecomment-1184657437
* @see https://alchemy.com/blog/how-to-polyfill-node-core-modules-in-webpack-5
*/
import webpack from 'webpack'
// import webpack from 'webpack'

const PURE_ESM_MODULES = [
'ipfs-geoip',
Expand Down Expand Up @@ -73,40 +73,40 @@ function modifyBabelLoaderRuleForTest (rules) {
})
}

function webpackOverride (config) {
const fallback = config.resolve.fallback || {}
export function webpackOverride (config) {
// const fallback = config.resolve.fallback || {}

Object.assign(fallback, {
stream: 'stream-browserify',
os: 'os-browserify/browser',
path: 'path-browserify',
crypto: 'crypto-browserify'
})
// Object.assign(fallback, {
// stream: 'stream-browserify',
// os: 'os-browserify/browser',
// path: 'path-browserify',
// crypto: 'crypto-browserify'
// })

config.resolve.fallback = fallback
// config.resolve.fallback = fallback

config.plugins = (config.plugins || []).concat([
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer']
})
])
// config.plugins = (config.plugins || []).concat([
// new webpack.ProvidePlugin({
// process: 'process/browser',
// Buffer: ['buffer', 'Buffer']
// })
// ])

config.module.rules = modifyBabelLoaderRuleForBuild(config.module.rules)
config.module.rules.push({
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: { presets: ['@babel/env', '@babel/preset-react'] }
})
// config.module.rules.push({
// test: /\.jsx?$/,
// exclude: /(node_modules|bower_components)/,
// loader: 'babel-loader',
// options: { presets: ['@babel/env', '@babel/preset-react'] }
// })

config.module.rules.push({
test: /\.m?js$/,
type: 'javascript/auto',
resolve: {
fullySpecified: false
}
})
// config.module.rules.push({
// test: /\.m?js$/,
// type: 'javascript/auto',
// resolve: {
// fullySpecified: false
// }
// })

// Instrument for code coverage in development mode
const REACT_APP_ENV = process.env.REACT_APP_ENV ?? process.env.NODE_ENV ?? 'development'
Expand All @@ -127,38 +127,38 @@ function webpackOverride (config) {
return config
}

const configOverride = {
webpack: webpackOverride,
jest: (config) => {
/**
* @type {import('jest').Config}
*/
return ({
...config,
setupFiles: [...config.setupFiles, 'fake-indexeddb/auto'],
moduleNameMapper: {
...config.moduleNameMapper,
'multiformats/basics': '<rootDir>/node_modules/multiformats/dist/src/basics.js',
'multiformats/bases/base32': '<rootDir>/node_modules/multiformats/dist/src/bases/base32.js',
'multiformats/bases/base58': '<rootDir>/node_modules/multiformats/dist/src/bases/base58.js',
'multiformats/cid': '<rootDir>/node_modules/multiformats/dist/src/cid.js',
'multiformats/hashes/digest': '<rootDir>/node_modules/multiformats/dist/src/hashes/digest.js',
'multiformats/hashes/sha2': '<rootDir>/node_modules/multiformats/dist/src/hashes/sha2.js',
'uint8arrays/alloc': '<rootDir>/node_modules/uint8arrays/dist/src/alloc.js',
'uint8arrays/concat': '<rootDir>/node_modules/uint8arrays/dist/src/concat.js',
'uint8arrays/equals': '<rootDir>/node_modules/uint8arrays/dist/src/equals.js',
'uint8arrays/from-string': '<rootDir>/node_modules/uint8arrays/dist/src/from-string.js',
'uint8arrays/to-string': '<rootDir>/node_modules/uint8arrays/dist/src/to-string.js',
'@chainsafe/is-ip/parse': '<rootDir>/node_modules/@chainsafe/is-ip/lib/parse.js',
// eslint-disable-next-line quote-props
'eventemitter3': '<rootDir>/node_modules/eventemitter3/dist/eventemitter3.esm.js'
},
transformIgnorePatterns: [
'node_module/(?!(eventemitter3)/).+\\.(js|jsx|mjs|cjs|ts|tsx)$',
'^.+\\.module\\.(css|sass|scss)$' // default
]
})
}
}
// const configOverride = {
// webpack: webpackOverride,
// jest: (config) => {
// /**
// * @type {import('jest').Config}
// */
// return ({
// ...config,
// setupFiles: [...config.setupFiles, 'fake-indexeddb/auto'],
// moduleNameMapper: {
// ...config.moduleNameMapper,
// 'multiformats/basics': '<rootDir>/node_modules/multiformats/dist/src/basics.js',
// 'multiformats/bases/base32': '<rootDir>/node_modules/multiformats/dist/src/bases/base32.js',
// 'multiformats/bases/base58': '<rootDir>/node_modules/multiformats/dist/src/bases/base58.js',
// 'multiformats/cid': '<rootDir>/node_modules/multiformats/dist/src/cid.js',
// 'multiformats/hashes/digest': '<rootDir>/node_modules/multiformats/dist/src/hashes/digest.js',
// 'multiformats/hashes/sha2': '<rootDir>/node_modules/multiformats/dist/src/hashes/sha2.js',
// 'uint8arrays/alloc': '<rootDir>/node_modules/uint8arrays/dist/src/alloc.js',
// 'uint8arrays/concat': '<rootDir>/node_modules/uint8arrays/dist/src/concat.js',
// 'uint8arrays/equals': '<rootDir>/node_modules/uint8arrays/dist/src/equals.js',
// 'uint8arrays/from-string': '<rootDir>/node_modules/uint8arrays/dist/src/from-string.js',
// 'uint8arrays/to-string': '<rootDir>/node_modules/uint8arrays/dist/src/to-string.js',
// '@chainsafe/is-ip/parse': '<rootDir>/node_modules/@chainsafe/is-ip/lib/parse.js',
// // eslint-disable-next-line quote-props
// 'eventemitter3': '<rootDir>/node_modules/eventemitter3/dist/eventemitter3.esm.js'
// },
// transformIgnorePatterns: [
// 'node_module/(?!(eventemitter3)/).+\\.(js|jsx|mjs|cjs|ts|tsx)$',
// '^.+\\.module\\.(css|sass|scss)$' // default
// ]
// })
// }
// }

export default configOverride
// export default configOverride
Loading
Loading