Skip to content

Commit

Permalink
update sdk build cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Jan 13, 2025
1 parent 7141dae commit 27455ef
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 42 deletions.
19 changes: 14 additions & 5 deletions esbuild.plugin.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const esmOnlyPackages = ['@thi.ng/memoize', '@thi.ng/cache'];
const esmOnlyPackages = [];
const esmOnlyNamespaces = ['@thi.ng'];

export function externalizePackages(except = []) {
const noExt = esmOnlyPackages.concat(except);
const noExtSet = new Set(noExt);
const esmOnly = esmOnlyPackages.concat(except);
const esmOnlySet = new Set(esmOnly);
return {
name: 'noExternal-plugin',
setup(build) {
Expand All @@ -15,8 +16,16 @@ export function externalizePackages(except = []) {
return;
}

if (noExtSet.has(args.path)) {
console.log('ⓘ Bundle external:', args.path);
const esmNs = esmOnlyNamespaces.find((ns) => args.path.startsWith(ns));
if (esmNs) {
return;
}

if (esmOnlySet.has(args.path)) {
const namespace = args.importer
.replace(args.resolveDir, '')
.replace('/', '');
console.log('ⓘ Found external import', args.path, 'in', namespace);
return;
}

Expand Down
11 changes: 10 additions & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ export const config = {
roots: ['<rootDir>'],
modulePaths: ['<rootDir>'],
moduleDirectories: ['node_modules'],
preset: 'ts-jest/presets/default-esm',
testMatch: ['**/__tests__/**/*.+(ts|js)', '**/?(*.)+(spec|test).+(ts|js)'],
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
tsconfig: 'tsconfig.json',
},
],
},
};
247 changes: 243 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions packages/sdk/esbuild.dev.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import esbuild from 'esbuild';
import { esmConfig, getPackageJson } from '../../esbuild.config.mjs';

const packageJson = getPackageJson(import.meta.url);
const peerDependencies = Object.keys(packageJson.peerDependencies);
const dependencies = Object.keys(packageJson.dependencies);

const mathDependencies = dependencies.filter((v) =>
v.startsWith('@galacticcouncil/math-')
);
import { esmConfig } from '../../esbuild.config.mjs';

const plugins = [];
const options = {
...esmConfig,
bundle: true,
sourcemap: true,
external: Object.keys(peerDependencies).concat(mathDependencies),
packages: 'external',
};

const ctx = await esbuild.context({ ...options, plugins });
Expand Down
15 changes: 4 additions & 11 deletions packages/sdk/esbuild.dist.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import esbuild from 'esbuild';
import { writeFileSync } from 'fs';
import { esmConfig, cjsConfig, getPackageJson } from '../../esbuild.config.mjs';

const packageJson = getPackageJson(import.meta.url);
const peerDependencies = Object.keys(packageJson.peerDependencies);
const dependencies = Object.keys(packageJson.dependencies);

const mathDependencies = dependencies.filter((v) =>
v.startsWith('@galacticcouncil/math-')
);
import { esmConfig, cjsConfig } from '../../esbuild.config.mjs';
import { externalizePackages } from '../../esbuild.plugin.mjs';

// ESM bundle
esbuild
.build({
...esmConfig,
bundle: true,
external: peerDependencies.concat(mathDependencies),
packages: 'external',
})
.then(({ metafile }) => {
writeFileSync('build-meta.json', JSON.stringify(metafile));
Expand All @@ -27,6 +20,6 @@ esbuild
.build({
...cjsConfig,
bundle: true,
external: peerDependencies.concat(mathDependencies),
plugins: [externalizePackages()],
})
.catch(() => process.exit(1));
Loading

0 comments on commit 27455ef

Please sign in to comment.