Skip to content

Commit

Permalink
Do not bundle library packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaspit committed Nov 12, 2024
1 parent 6f7ec74 commit c2d278f
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 19 deletions.
87 changes: 87 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"build": "tsup-node",
"dev": "tsup-node --watch",
"dev": "tsup-node --watch --sourcemap",
"check-types": "tsc --noEmit",
"lint": "eslint .",
"test": "vitest",
Expand All @@ -37,6 +37,7 @@
"@repo/eslint-config": "*",
"@repo/typescript-config": "*",
"@vitest/coverage-v8": "^2.1.4",
"esbuild-fix-imports-plugin": "^1.0.6",
"eslint": "^9.9.1",
"tsup": "^8.3.0",
"typescript": "^5.5.4",
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/workspace/localizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Localizer {
await this.i18n.loadNamespaces(Array.from(this.backend.namespaces));
}

addNamespace(namespace: string, loader: (language: string) => Promise<unknown>): void {
addNamespace(namespace: string, loader: (language: string) => unknown): void {
if (this.i18n.hasLoadedNamespace(namespace)) {
return;
}
Expand All @@ -43,7 +43,7 @@ export class Localizer {
}

class LocalBackend {
private readonly namespaceLoaders = new Map<string, (language: string) => Promise<unknown>>();
private readonly namespaceLoaders = new Map<string, (language: string) => unknown>();
readonly type = 'backend';

get namespaces(): Iterable<string> {
Expand All @@ -54,7 +54,7 @@ class LocalBackend {
// do nothing
}

addNamespace(namespace: string, loader: (language: string) => Promise<unknown>): void {
addNamespace(namespace: string, loader: (language: string) => unknown): void {
this.namespaceLoaders.set(namespace, loader);
}

Expand All @@ -64,8 +64,11 @@ class LocalBackend {
callback(new Error(`No loader for namespace ${namespace}`));
return;
}
loader(language)
Promise.resolve(loader(language))
.then((data) => {
if (data != null && typeof data === 'object' && 'default' in data) {
data = data.default;
}
callback(null, data);
})
.catch(callback);
Expand Down
7 changes: 4 additions & 3 deletions packages/core/tsup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { fixImportsPlugin } from 'esbuild-fix-imports-plugin';
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
entry: ['src/**/*.ts', '!src/**/*.test.ts'],
dts: true,
clean: true,
format: ['esm', 'cjs'],
bundle: true,
sourcemap: true,
bundle: false,
esbuildPlugins: [fixImportsPlugin()],
});
4 changes: 3 additions & 1 deletion packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"build": "tsup-node",
"dev": "tsup-node --watch",
"dev": "tsup-node --watch --sourcemap",
"check-types": "tsc --noEmit",
"lint": "eslint .",
"test": "vitest",
Expand All @@ -36,6 +36,8 @@
"@repo/eslint-config": "*",
"@repo/typescript-config": "*",
"@vitest/coverage-v8": "^2.1.4",
"copy-folder-util": "^1.1.4",
"esbuild-fix-imports-plugin": "^1.0.6",
"eslint": "^9.9.1",
"tsup": "^8.3.0",
"typescript": "^5.5.4",
Expand Down
5 changes: 4 additions & 1 deletion packages/examples/src/verse-order-diagnostic-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export class VerseOrderDiagnosticProvider implements DiagnosticProvider {
}

init(): Promise<void> {
this.localizer.addNamespace('verseOrder', (language: string) => import(`./locales/${language}/verse-order.json`));
this.localizer.addNamespace(
'verseOrder',
(language: string) => import(`./locales/${language}/verse-order.json`, { with: { type: 'json' } }),
);
return Promise.resolve();
}

Expand Down
3 changes: 1 addition & 2 deletions packages/examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"resolveJsonModule": true
"rootDir": "src"
}
}
13 changes: 10 additions & 3 deletions packages/examples/tsup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { fixImportsPlugin } from 'esbuild-fix-imports-plugin';
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
entry: ['src/**/*.ts', '!src/**/*.test.ts'],
dts: true,
clean: true,
format: ['esm', 'cjs'],
bundle: true,
sourcemap: true,
bundle: false,
onSuccess: 'copy-folder src/locales dist/locales',
esbuildPlugins: [fixImportsPlugin()],
esbuildOptions(options) {
options.supported = {
'import-attributes': true,
};
},
});
3 changes: 2 additions & 1 deletion packages/usfm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"build": "tsup-node",
"dev": "tsup-node --watch",
"dev": "tsup-node --watch --sourcemap",
"check-types": "tsc --noEmit",
"lint": "eslint .",
"test": "vitest",
Expand All @@ -37,6 +37,7 @@
"@repo/eslint-config": "*",
"@repo/typescript-config": "*",
"@vitest/coverage-v8": "^2.1.4",
"esbuild-fix-imports-plugin": "^1.0.6",
"eslint": "^9.9.1",
"tsup": "^8.3.0",
"typescript": "^5.5.4",
Expand Down
7 changes: 4 additions & 3 deletions packages/usfm/tsup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { fixImportsPlugin } from 'esbuild-fix-imports-plugin';
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
entry: ['src/**/*.ts', '!src/**/*.test.ts'],
dts: true,
clean: true,
format: ['esm', 'cjs'],
bundle: true,
sourcemap: true,
bundle: false,
esbuildPlugins: [fixImportsPlugin()],
});

0 comments on commit c2d278f

Please sign in to comment.