Skip to content

Commit

Permalink
Merge pull request #233 from GordonSmith/ESBUILD_PLUGIN_SFX_WASM
Browse files Browse the repository at this point in the history
feat: Convert to monorepo
  • Loading branch information
GordonSmith authored Aug 12, 2024
2 parents b0d8c38 + 5e20bbd commit a84bb3e
Show file tree
Hide file tree
Showing 135 changed files with 12,296 additions and 2,586 deletions.
18 changes: 11 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/.nyc_output
.nyc_output/
/.vscode/c_cpp_properties.json
/.vscode/ipch
/bin
/build
.nx/
bin/
build/
/coverage
/dist
/dist-test
dist/
dist-test/
/docs/.vitepress/cache
/docs/.vitepress/dist
/docs/classes
Expand All @@ -15,14 +16,17 @@
/docs/README.md
/emsdk*
/lib-*
/node_modules
node_modules/
/rust
/third-party
/src-ts/*.wasm.ts
/tmp
/types
types/
/wasi-sdk*
/wit-bindgen
/vcpkg
.coveralls.yml
*.tsbuildinfo

.nx/cache
.nx/workspace-data
7 changes: 0 additions & 7 deletions .nycrc

This file was deleted.

14 changes: 4 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,8 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(PACK_MODE "-d")
endif ()

function(packWasm targetID)
add_custom_target(sfx-${targetID} ALL
COMMAND node ./utils/sfx-wasm.js ${PACK_MODE} ${CMAKE_CURRENT_BINARY_DIR}/${targetID}.wasm > ${REPO_DIR}/build/${targetID}.wasm.js
WORKING_DIRECTORY ${REPO_DIR}
COMMENT "SFX Wasm ${targetID}"
)

add_dependencies(sfx-${targetID} ${targetID} base91lib zstdlib)
endfunction ()

add_subdirectory(src-cpp)
add_subdirectory(packages/base91/src-cpp)
add_subdirectory(packages/expat/src-cpp)
add_subdirectory(packages/graphviz/src-cpp)
add_subdirectory(packages/zstd/src-cpp)
1 change: 0 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"hidden": true,
"generator": "Ninja",
"cacheVariables": {
"REPO_DIR": "${sourceDir}",
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake"
}
},
Expand Down
62 changes: 11 additions & 51 deletions esbuild.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as process from "process";
import { readFileSync } from "fs";
import * as esbuild from "esbuild";
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
import { rebuildLogger, sfxWasm } from "@hpcc-js/esbuild-plugins";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";

Expand Down Expand Up @@ -33,73 +35,30 @@ const isDevelopment = argv.mode === "development";
const isProduction = !isDevelopment;
const isWatch = argv.watch;

// plugins ---
const excludeSourceMapPlugin = ({ filter }) => ({
name: "excludeSourceMapPlugin",

setup(build) {
build.onLoad({ filter }, (args) => {
return {
contents:
readFileSync(args.path, "utf8") +
"\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",
loader: "default",
};
});
},
});

const esbuildProblemMatcherPlugin = ({ filter }) => ({
name: "esbuild-problem-matcher",

setup(build) {
build.onStart(() => {
console.log("[watch] build started");
});
build.onEnd((result) => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(` ${location.file}:${location.line}:${location.column}:`);
});
console.log("[watch] build finished");
});
},
});

function rebuildNotify(config) {
return {
name: "rebuild-notify",

setup(build) {
build.onEnd(result => {
console.log(`Built ${config.outfile}`);
});
},
};
}

// helpers ---
function build(config) {
isDevelopment && console.log("Start: ", config.entryPoints[0], config.outfile);
return esbuild.build({
...config,
sourcemap: "external",
sourcemap: "linked",
plugins: [
...(config.plugins ?? []),
sfxWasm()
]
}).then(() => {
isDevelopment && console.log("Stop: ", config.entryPoints[0], config.outfile);
});
}

async function watch(config) {
await esbuild.build(config);
await build(config);
return esbuild.context({
...config,
sourcemap: "linked",
sourcemap: "external",
plugins: [
...(config.plugins ?? []),
rebuildNotify(config),
rebuildLogger(config),
sfxWasm()
]
}).then(ctx => {
return ctx.watch();
Expand All @@ -120,14 +79,15 @@ function browserTpl(input, output, format, globalName = "", external = []) {
globalName,
bundle: true,
minify: isProduction,
external
external,
plugins: format === "umd" ? [umdWrapper()] : []
});
}

function browserBoth(input, output, globalName = undefined, external = []) {
return Promise.all([
browserTpl(input, output, "esm", globalName, external),
browserTpl(input, output, "iife", globalName, external)
browserTpl(input, output, "umd", globalName, external)
]);
}

Expand Down
9 changes: 9 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ export default [
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unused-vars": [
"error", // or "error"
{
"argsIgnorePattern": "^_",
// "varsIgnorePattern": "^_",
// "caughtErrorsIgnorePattern": "^_"
}
]
}
},
];
17 changes: 17 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"command": {
"version": {
"conventionalCommits": true,
"gitRemote": "upstream",
"ignoreChanges": [
"__package__.ts",
"*.md"
],
"allowBranch": "trunk"
},
"publish": {}
},
"version": "independent"
}
Loading

0 comments on commit a84bb3e

Please sign in to comment.