@gjsify/esbuild-plugin-gjsify 0.0.2
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.
- package/dist/cjs/index.cjs +11752 -0
- package/dist/esm/index.mjs +11726 -0
- package/dist/types/alias-plugin.d.ts +2 -0
- package/dist/types/app/browser.d.ts +3 -0
- package/dist/types/app/deno.d.ts +3 -0
- package/dist/types/app/gjs.d.ts +3 -0
- package/dist/types/app/index.d.ts +4 -0
- package/dist/types/app/node.d.ts +3 -0
- package/dist/types/debug-plugin.d.ts +2 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/lib/cjs.d.ts +3 -0
- package/dist/types/lib/esm.d.ts +3 -0
- package/dist/types/lib/index.d.ts +2 -0
- package/dist/types/plugin.d.ts +4 -0
- package/dist/types/types/app.d.ts +1 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/plugin-options.d.ts +17 -0
- package/dist/types/types/resolve-alias-options.d.ts +2 -0
- package/dist/types/utils/alias.d.ts +15 -0
- package/dist/types/utils/entry-points.d.ts +5 -0
- package/dist/types/utils/extension.d.ts +8 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/esbuild.mjs +49 -0
- package/package.json +46 -0
- package/src/alias-plugin.ts +68 -0
- package/src/app/browser.ts +60 -0
- package/src/app/deno.ts +60 -0
- package/src/app/gjs.ts +66 -0
- package/src/app/index.ts +4 -0
- package/src/app/node.ts +63 -0
- package/src/index.ts +7 -0
- package/src/lib/cjs.ts +46 -0
- package/src/lib/esm.ts +44 -0
- package/src/lib/index.ts +2 -0
- package/src/plugin.ts +43 -0
- package/src/types/app.ts +1 -0
- package/src/types/index.ts +3 -0
- package/src/types/plugin-options.ts +18 -0
- package/src/types/resolve-alias-options.ts +1 -0
- package/src/utils/alias.ts +59 -0
- package/src/utils/entry-points.ts +33 -0
- package/src/utils/extension.ts +7 -0
- package/src/utils/index.ts +3 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type App = 'gjs' | 'node' | 'deno' | 'browser';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { App } from './app.js';
|
|
2
|
+
import type { DeepkitPluginOptions } from '@gjsify/esbuild-plugin-deepkit';
|
|
3
|
+
export interface PluginOptions extends DeepkitPluginOptions {
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
app?: App;
|
|
6
|
+
aliases?: Record<string, string>;
|
|
7
|
+
/** An array of glob patterns to exclude matches and aliases */
|
|
8
|
+
exclude?: string[];
|
|
9
|
+
jsExtension?: string;
|
|
10
|
+
/** Override the format, only be considered if the target app platform is `'node'`, otherwise it is always `'esm'` */
|
|
11
|
+
format?: 'esm' | 'cjs';
|
|
12
|
+
/**
|
|
13
|
+
* Library Mode
|
|
14
|
+
* Use this if you want to build a library for Gjsify instead of an end user application.
|
|
15
|
+
*/
|
|
16
|
+
library?: 'esm' | 'cjs';
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ResolveAliasOptions } from '../types/index.js';
|
|
2
|
+
export declare const setNodeAliasPrefix: (ALIASES: Record<string, string>) => Record<string, string>;
|
|
3
|
+
export declare const getAliasesForGjs: (options: ResolveAliasOptions) => {
|
|
4
|
+
[x: string]: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const getAliasesForDeno: (options: ResolveAliasOptions) => {
|
|
7
|
+
[x: string]: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const getAliasesForNode: (options: ResolveAliasOptions) => {
|
|
10
|
+
[x: string]: string;
|
|
11
|
+
};
|
|
12
|
+
/** Array of Node.js build in module names (also with node: prefix) */
|
|
13
|
+
export declare const externalNode: string[];
|
|
14
|
+
/** Array of NPM module names for which we have our own implementation */
|
|
15
|
+
export declare const externalNPM: string[];
|
package/esbuild.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { build } from 'esbuild';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import { extname, dirname } from 'path';
|
|
4
|
+
import { EXTERNALS_NODE } from '@gjsify/resolve-npm';
|
|
5
|
+
|
|
6
|
+
const pkg = JSON.parse(
|
|
7
|
+
await readFile(
|
|
8
|
+
new URL('./package.json', import.meta.url), 'utf8'
|
|
9
|
+
)
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
if (!pkg.main && !pkg.module) {
|
|
13
|
+
throw new Error("package.json: The main or module property is required!");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const baseConfig = {
|
|
17
|
+
entryPoints: ['src/index.ts'],
|
|
18
|
+
bundle: true,
|
|
19
|
+
minify: false,
|
|
20
|
+
external: [
|
|
21
|
+
...EXTERNALS_NODE,
|
|
22
|
+
'typescript',
|
|
23
|
+
'@deepkit/type-compiler',
|
|
24
|
+
'esbuild',
|
|
25
|
+
// '@gjsify/resolve-npm', can't be required in cjs builds
|
|
26
|
+
'@gjsify/esbuild-plugin-transform-ext',
|
|
27
|
+
'@gjsify/esbuild-plugin-deno-loader',
|
|
28
|
+
'@gjsify/esbuild-plugin-deepkit',
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (pkg.main) {
|
|
33
|
+
build({
|
|
34
|
+
...baseConfig,
|
|
35
|
+
outdir: dirname(pkg.main),
|
|
36
|
+
format: 'cjs',
|
|
37
|
+
outExtension: {'.js': extname(pkg.main)},
|
|
38
|
+
platform: "node",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (pkg.module) {
|
|
43
|
+
build({
|
|
44
|
+
...baseConfig,
|
|
45
|
+
outdir: dirname(pkg.module),
|
|
46
|
+
format: 'esm',
|
|
47
|
+
outExtension: {'.js': extname(pkg.module)},
|
|
48
|
+
});
|
|
49
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gjsify/esbuild-plugin-gjsify",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Deepkit type compiler plugin for esbuild",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/cjs/index.cjs",
|
|
7
|
+
"module": "dist/esm/index.mjs",
|
|
8
|
+
"types": "dist/types/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"clear": "rm -rf dist tsconfig.tsbuildinfo",
|
|
11
|
+
"print:name": "echo '@gjsify/esbuild-plugin-gjsify'",
|
|
12
|
+
"test": "yarn print:name && echo 'nothing to do'",
|
|
13
|
+
"build": "yarn print:name && yarn build:js && yarn build:types",
|
|
14
|
+
"build:js": "node esbuild.mjs",
|
|
15
|
+
"build:types": "tsc --emitDeclarationOnly || exit 0"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"gjs",
|
|
19
|
+
"gjsify",
|
|
20
|
+
"esbuild"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@gjsify/esbuild-plugin-deepkit": "^0.0.2",
|
|
24
|
+
"@gjsify/esbuild-plugin-deno-loader": "^0.0.2",
|
|
25
|
+
"@gjsify/esbuild-plugin-transform-ext": "^0.0.2",
|
|
26
|
+
"assert": "^2.0.0",
|
|
27
|
+
"constants-browserify": "^1.0.0",
|
|
28
|
+
"core-js": "^3.31.0",
|
|
29
|
+
"crypto-browserify": "^3.12.0",
|
|
30
|
+
"esm": "^3.2.25",
|
|
31
|
+
"fast-glob": "^3.2.12",
|
|
32
|
+
"lodash": "^4.17.21",
|
|
33
|
+
"micromatch": "^4.0.5",
|
|
34
|
+
"path-browserify": "^1.0.1",
|
|
35
|
+
"punycode": "^2.3.0",
|
|
36
|
+
"stream-browserify": "^3.0.0",
|
|
37
|
+
"string_decoder": "^1.3.0",
|
|
38
|
+
"test": "^3.3.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/lodash": "^4.14.195",
|
|
42
|
+
"@types/micromatch": "^4.0.2",
|
|
43
|
+
"esbuild": "^0.18.2",
|
|
44
|
+
"typescript": "^5.1.3"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import { realpath } from "fs/promises";
|
|
3
|
+
|
|
4
|
+
import type { Plugin } from "esbuild";
|
|
5
|
+
|
|
6
|
+
export const aliasPlugin = (aliasObj: Record<string, string>) => {
|
|
7
|
+
const aliases = Object.keys(aliasObj);
|
|
8
|
+
const re = new RegExp(`^(${aliases.map(x => escapeRegExp(x)).join('|')})$`);
|
|
9
|
+
|
|
10
|
+
const plugin: Plugin = {
|
|
11
|
+
name: 'alias',
|
|
12
|
+
setup(build) {
|
|
13
|
+
// we do not register 'file' namespace here, because the root file won't be processed
|
|
14
|
+
// https://github.com/evanw/esbuild/issues/791
|
|
15
|
+
build.onResolve({ filter: re }, async (args) => {
|
|
16
|
+
let resolvedAliasPath = aliasObj[args.path];
|
|
17
|
+
|
|
18
|
+
let namespace = args.namespace;
|
|
19
|
+
|
|
20
|
+
if (resolvedAliasPath) {
|
|
21
|
+
|
|
22
|
+
if (resolvedAliasPath.startsWith('http://')) {
|
|
23
|
+
namespace = 'http';
|
|
24
|
+
resolvedAliasPath = resolvedAliasPath.slice(5)
|
|
25
|
+
} else if (resolvedAliasPath.startsWith('https://')) {
|
|
26
|
+
namespace = 'https';
|
|
27
|
+
resolvedAliasPath = resolvedAliasPath.slice(6)
|
|
28
|
+
} else {
|
|
29
|
+
const resolvedAlias = (await build.resolve(resolvedAliasPath, {
|
|
30
|
+
importer: args.importer,
|
|
31
|
+
kind: args.kind,
|
|
32
|
+
namespace: namespace,
|
|
33
|
+
resolveDir: args.resolveDir,
|
|
34
|
+
pluginData: args.pluginData,
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
if (resolvedAlias.errors) {
|
|
38
|
+
return resolvedAlias;
|
|
39
|
+
} else {
|
|
40
|
+
resolvedAliasPath = resolvedAlias.path;
|
|
41
|
+
namespace = resolvedAlias.namespace;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (existsSync(resolvedAliasPath)) {
|
|
46
|
+
resolvedAliasPath = await realpath(resolvedAliasPath);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// console.debug(`resolvedAliasPath: ${args.path} -> ${resolvedAliasPath}`);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
path: resolvedAliasPath,
|
|
53
|
+
namespace: namespace,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return null;
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return plugin;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
function escapeRegExp(str: string) {
|
|
66
|
+
// $& means the whole matched string
|
|
67
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
68
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { aliasPlugin } from '../alias-plugin.js';
|
|
2
|
+
import { denoPlugin } from '@gjsify/esbuild-plugin-deno-loader';
|
|
3
|
+
import * as deepkitPlugin from '@gjsify/esbuild-plugin-deepkit';
|
|
4
|
+
import { merge } from "lodash";
|
|
5
|
+
import { globToEntryPoints } from "../utils/index.js";
|
|
6
|
+
|
|
7
|
+
// Types
|
|
8
|
+
import type { PluginBuild, BuildOptions } from "esbuild";
|
|
9
|
+
import type { PluginOptions } from '../types/plugin-options.js';
|
|
10
|
+
|
|
11
|
+
export const setupForBrowser = async (build: PluginBuild, pluginOptions: PluginOptions) => {
|
|
12
|
+
|
|
13
|
+
const external = [];
|
|
14
|
+
|
|
15
|
+
pluginOptions.aliases ||= {};
|
|
16
|
+
pluginOptions.exclude ||= [];
|
|
17
|
+
|
|
18
|
+
// Set default options
|
|
19
|
+
const esbuildOptions: BuildOptions = {
|
|
20
|
+
format: 'esm',
|
|
21
|
+
bundle: true,
|
|
22
|
+
minify: false,
|
|
23
|
+
sourcemap: false,
|
|
24
|
+
treeShaking: true,
|
|
25
|
+
preserveSymlinks: false, // false means follow symlinks
|
|
26
|
+
target: [ "esnext" ],
|
|
27
|
+
platform: "browser",
|
|
28
|
+
mainFields: ['browser', 'module', 'main'],
|
|
29
|
+
conditions: ['import', 'browser'],
|
|
30
|
+
external,
|
|
31
|
+
loader: {
|
|
32
|
+
'.ts': 'ts',
|
|
33
|
+
'.mts': 'ts',
|
|
34
|
+
'.cts': 'ts',
|
|
35
|
+
'.tsx': 'ts',
|
|
36
|
+
'.mtsx': 'ts',
|
|
37
|
+
'.ctsx': 'ts',
|
|
38
|
+
'.mjs': 'ts',
|
|
39
|
+
'.cjs': 'ts',
|
|
40
|
+
'.js': 'ts',
|
|
41
|
+
},
|
|
42
|
+
inject: [],
|
|
43
|
+
define: {
|
|
44
|
+
global: 'globalThis',
|
|
45
|
+
window: 'globalThis',
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
merge(build.initialOptions, esbuildOptions);
|
|
50
|
+
|
|
51
|
+
build.initialOptions.entryPoints = await globToEntryPoints(build.initialOptions.entryPoints, pluginOptions.exclude)
|
|
52
|
+
|
|
53
|
+
const aliases = {...pluginOptions.aliases};
|
|
54
|
+
|
|
55
|
+
if(pluginOptions.debug) console.debug("initialOptions", build.initialOptions);
|
|
56
|
+
|
|
57
|
+
await aliasPlugin(aliases).setup(build);
|
|
58
|
+
await denoPlugin({reflection: pluginOptions.reflection}).setup(build);
|
|
59
|
+
await deepkitPlugin.deepkitPlugin({reflection: pluginOptions.reflection}).setup(build);
|
|
60
|
+
}
|
package/src/app/deno.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { aliasPlugin } from '../alias-plugin.js';
|
|
2
|
+
import { denoPlugin } from '@gjsify/esbuild-plugin-deno-loader';
|
|
3
|
+
import * as deepkitPlugin from '@gjsify/esbuild-plugin-deepkit';
|
|
4
|
+
import { merge } from "lodash";
|
|
5
|
+
|
|
6
|
+
// Types
|
|
7
|
+
import type { PluginBuild, BuildOptions } from "esbuild";
|
|
8
|
+
import type { PluginOptions } from '../types/plugin-options.js';
|
|
9
|
+
import { getAliasesForDeno, globToEntryPoints } from "../utils/index.js";
|
|
10
|
+
|
|
11
|
+
export const setupForDeno = async (build: PluginBuild, pluginOptions: PluginOptions) => {
|
|
12
|
+
|
|
13
|
+
const external = [];
|
|
14
|
+
|
|
15
|
+
pluginOptions.aliases ||= {};
|
|
16
|
+
pluginOptions.exclude ||= [];
|
|
17
|
+
|
|
18
|
+
// Set default options
|
|
19
|
+
const esbuildOptions: BuildOptions = {
|
|
20
|
+
format: 'esm',
|
|
21
|
+
bundle: true,
|
|
22
|
+
minify: false,
|
|
23
|
+
sourcemap: false,
|
|
24
|
+
treeShaking: true,
|
|
25
|
+
preserveSymlinks: false, // false means follow symlinks
|
|
26
|
+
target: [ "esnext" ],
|
|
27
|
+
platform: "neutral",
|
|
28
|
+
mainFields: ['module', 'main'],
|
|
29
|
+
conditions: ['module','import'],
|
|
30
|
+
external,
|
|
31
|
+
loader: {
|
|
32
|
+
'.ts': 'ts',
|
|
33
|
+
'.mts': 'ts',
|
|
34
|
+
'.cts': 'ts',
|
|
35
|
+
'.tsx': 'ts',
|
|
36
|
+
'.mtsx': 'ts',
|
|
37
|
+
'.ctsx': 'ts',
|
|
38
|
+
'.mjs': 'ts',
|
|
39
|
+
'.cjs': 'ts',
|
|
40
|
+
'.js': 'ts',
|
|
41
|
+
},
|
|
42
|
+
inject: [],
|
|
43
|
+
define: {
|
|
44
|
+
global: 'globalThis',
|
|
45
|
+
window: 'globalThis',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
merge(build.initialOptions, esbuildOptions);
|
|
50
|
+
|
|
51
|
+
build.initialOptions.entryPoints = await globToEntryPoints(build.initialOptions.entryPoints, pluginOptions.exclude)
|
|
52
|
+
|
|
53
|
+
const aliases = {...getAliasesForDeno({external}), ...pluginOptions.aliases};
|
|
54
|
+
|
|
55
|
+
if(pluginOptions.debug) console.debug("initialOptions", build.initialOptions);
|
|
56
|
+
|
|
57
|
+
await aliasPlugin(aliases).setup(build);
|
|
58
|
+
await denoPlugin({reflection: pluginOptions.reflection}).setup(build);
|
|
59
|
+
await deepkitPlugin.deepkitPlugin({reflection: pluginOptions.reflection}).setup(build);
|
|
60
|
+
}
|
package/src/app/gjs.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { aliasPlugin } from '../alias-plugin.js';
|
|
2
|
+
import { denoPlugin } from '@gjsify/esbuild-plugin-deno-loader';
|
|
3
|
+
import * as deepkitPlugin from '@gjsify/esbuild-plugin-deepkit';
|
|
4
|
+
import { merge } from "lodash";
|
|
5
|
+
import { getAliasesForGjs, globToEntryPoints } from "../utils/index.js";
|
|
6
|
+
|
|
7
|
+
// Types
|
|
8
|
+
import type { PluginBuild, BuildOptions } from "esbuild";
|
|
9
|
+
import type { PluginOptions } from '../types/plugin-options.js';
|
|
10
|
+
|
|
11
|
+
export const setupForGjs = async (build: PluginBuild, pluginOptions: PluginOptions) => {
|
|
12
|
+
|
|
13
|
+
const external = ['gi://*', 'cairo', 'gettext', 'system'];
|
|
14
|
+
|
|
15
|
+
pluginOptions.aliases ||= {};
|
|
16
|
+
pluginOptions.exclude ||= [];
|
|
17
|
+
|
|
18
|
+
// Set default options
|
|
19
|
+
const esbuildOptions: BuildOptions = {
|
|
20
|
+
format: 'esm', // On Gjs we only support esm
|
|
21
|
+
bundle: true,
|
|
22
|
+
metafile: true,
|
|
23
|
+
minify: false,
|
|
24
|
+
sourcemap: false,
|
|
25
|
+
treeShaking: true,
|
|
26
|
+
preserveSymlinks: false, // false means follow symlinks
|
|
27
|
+
// firefox60 // Since GJS 1.53.90
|
|
28
|
+
// firefox68 // Since GJS 1.63.90
|
|
29
|
+
// firefox78 // Since GJS 1.65.90
|
|
30
|
+
// firefox91 // Since GJS 1.71.1
|
|
31
|
+
// firefox102 // Since GJS 1.73.2
|
|
32
|
+
target: [ "firefox102" ],
|
|
33
|
+
platform: "neutral",
|
|
34
|
+
mainFields: ['module', 'main'],
|
|
35
|
+
// https://esbuild.github.io/api/#conditions
|
|
36
|
+
conditions: ['module','import'],
|
|
37
|
+
external,
|
|
38
|
+
loader: {
|
|
39
|
+
'.ts': 'ts',
|
|
40
|
+
'.mts': 'ts',
|
|
41
|
+
'.cts': 'ts',
|
|
42
|
+
'.tsx': 'ts',
|
|
43
|
+
'.mtsx': 'ts',
|
|
44
|
+
'.ctsx': 'ts',
|
|
45
|
+
'.mjs': 'ts',
|
|
46
|
+
'.cjs': 'ts',
|
|
47
|
+
'.js': 'ts',
|
|
48
|
+
},
|
|
49
|
+
define: {
|
|
50
|
+
global: 'globalThis',
|
|
51
|
+
window: 'globalThis',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
merge(build.initialOptions, esbuildOptions);
|
|
56
|
+
|
|
57
|
+
build.initialOptions.entryPoints = await globToEntryPoints(build.initialOptions.entryPoints, pluginOptions.exclude);
|
|
58
|
+
|
|
59
|
+
const aliases = {...getAliasesForGjs({external}), ...pluginOptions.aliases};
|
|
60
|
+
|
|
61
|
+
if(pluginOptions.debug) console.debug("initialOptions", build.initialOptions);
|
|
62
|
+
|
|
63
|
+
await aliasPlugin(aliases).setup(build);
|
|
64
|
+
await denoPlugin({reflection: pluginOptions.reflection}).setup(build);
|
|
65
|
+
await deepkitPlugin.deepkitPlugin({reflection: pluginOptions.reflection}).setup(build);
|
|
66
|
+
}
|
package/src/app/index.ts
ADDED
package/src/app/node.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
|
|
2
|
+
import { aliasPlugin } from '../alias-plugin.js';
|
|
3
|
+
import { denoPlugin } from '@gjsify/esbuild-plugin-deno-loader';
|
|
4
|
+
import * as deepkitPlugin from '@gjsify/esbuild-plugin-deepkit';
|
|
5
|
+
import { merge } from "lodash";
|
|
6
|
+
import { getAliasesForNode, globToEntryPoints } from "../utils/index.js";
|
|
7
|
+
import { EXTERNALS_NODE } from "@gjsify/resolve-npm";
|
|
8
|
+
|
|
9
|
+
// Types
|
|
10
|
+
import type { PluginBuild, BuildOptions } from "esbuild";
|
|
11
|
+
import type { PluginOptions } from '../types/plugin-options.js';
|
|
12
|
+
|
|
13
|
+
export const setupForNode = async (build: PluginBuild, pluginOptions: PluginOptions) => {
|
|
14
|
+
|
|
15
|
+
const external = [...EXTERNALS_NODE, 'gi://*'];
|
|
16
|
+
|
|
17
|
+
pluginOptions.aliases ||= {};
|
|
18
|
+
pluginOptions.exclude ||= [];
|
|
19
|
+
|
|
20
|
+
const format = pluginOptions.format || 'esm';
|
|
21
|
+
|
|
22
|
+
// Set default options
|
|
23
|
+
const esbuildOptions: BuildOptions = {
|
|
24
|
+
format,
|
|
25
|
+
bundle: true,
|
|
26
|
+
minify: false,
|
|
27
|
+
sourcemap: false,
|
|
28
|
+
treeShaking: true,
|
|
29
|
+
preserveSymlinks: false, // false means follow symlinks
|
|
30
|
+
target: [ "node18" ],
|
|
31
|
+
platform: "node",
|
|
32
|
+
mainFields: format === 'esm' ? ['module', 'main'] : ['main', 'module', 'browser'],
|
|
33
|
+
conditions: format === 'esm' ? ['module', 'import'] : ['require'],
|
|
34
|
+
external,
|
|
35
|
+
loader: {
|
|
36
|
+
'.ts': 'ts',
|
|
37
|
+
'.mts': 'ts',
|
|
38
|
+
'.cts': 'ts',
|
|
39
|
+
'.tsx': 'ts',
|
|
40
|
+
'.mtsx': 'ts',
|
|
41
|
+
'.ctsx': 'ts',
|
|
42
|
+
'.mjs': 'ts',
|
|
43
|
+
'.cjs': 'ts',
|
|
44
|
+
'.js': 'ts',
|
|
45
|
+
},
|
|
46
|
+
define: {
|
|
47
|
+
global: 'globalThis',
|
|
48
|
+
window: 'globalThis',
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
merge(build.initialOptions, esbuildOptions);
|
|
53
|
+
|
|
54
|
+
build.initialOptions.entryPoints = await globToEntryPoints(build.initialOptions.entryPoints, pluginOptions.exclude)
|
|
55
|
+
|
|
56
|
+
const aliases = {...getAliasesForNode({external}), ...pluginOptions.aliases};
|
|
57
|
+
|
|
58
|
+
if(pluginOptions.debug) console.debug("initialOptions", build.initialOptions);
|
|
59
|
+
|
|
60
|
+
await aliasPlugin(aliases).setup(build);
|
|
61
|
+
await denoPlugin({reflection: pluginOptions.reflection}).setup(build);
|
|
62
|
+
await deepkitPlugin.deepkitPlugin({reflection: pluginOptions.reflection}).setup(build);
|
|
63
|
+
}
|
package/src/index.ts
ADDED
package/src/lib/cjs.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { aliasPlugin } from '../alias-plugin.js';
|
|
2
|
+
import { transformExtPlugin } from '@gjsify/esbuild-plugin-transform-ext';
|
|
3
|
+
import { merge } from "lodash";
|
|
4
|
+
import { getJsExtensions, globToEntryPoints } from "../utils/index.js";
|
|
5
|
+
|
|
6
|
+
// Types
|
|
7
|
+
import type { PluginBuild, BuildOptions } from "esbuild";
|
|
8
|
+
import type { PluginOptions } from '../types/plugin-options.js';
|
|
9
|
+
|
|
10
|
+
export const setupCjsLib = async (build: PluginBuild, pluginOptions: PluginOptions) => {
|
|
11
|
+
|
|
12
|
+
pluginOptions.aliases ||= {};
|
|
13
|
+
pluginOptions.exclude ||= [];
|
|
14
|
+
|
|
15
|
+
const esbuildOptions: BuildOptions = {
|
|
16
|
+
bundle: false,
|
|
17
|
+
splitting: false, // only works with esm, see https://esbuild.github.io/api/#splitting
|
|
18
|
+
minify: false,
|
|
19
|
+
sourcemap: false,
|
|
20
|
+
loader: {
|
|
21
|
+
'.ts': 'ts',
|
|
22
|
+
'.mts': 'ts',
|
|
23
|
+
'.cts': 'ts',
|
|
24
|
+
'.tsx': 'ts',
|
|
25
|
+
'.mtsx': 'ts',
|
|
26
|
+
'.ctsx': 'ts',
|
|
27
|
+
'.mjs': 'ts',
|
|
28
|
+
'.cjs': 'ts',
|
|
29
|
+
'.js': 'ts',
|
|
30
|
+
},
|
|
31
|
+
target: ['esnext'],
|
|
32
|
+
platform: "browser",
|
|
33
|
+
// https://esbuild.github.io/api/#conditions
|
|
34
|
+
conditions: ['require'],
|
|
35
|
+
format: 'cjs'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
merge(build.initialOptions, esbuildOptions);
|
|
39
|
+
|
|
40
|
+
build.initialOptions.entryPoints = await globToEntryPoints(build.initialOptions.entryPoints, pluginOptions.exclude)
|
|
41
|
+
|
|
42
|
+
if(pluginOptions.debug) console.debug("initialOptions", build.initialOptions);
|
|
43
|
+
|
|
44
|
+
await aliasPlugin(pluginOptions.aliases).setup(build);
|
|
45
|
+
await transformExtPlugin({ outExtension: getJsExtensions(pluginOptions.jsExtension) }).setup(build);
|
|
46
|
+
}
|
package/src/lib/esm.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { aliasPlugin } from '../alias-plugin.js';
|
|
2
|
+
import { transformExtPlugin } from '@gjsify/esbuild-plugin-transform-ext';
|
|
3
|
+
import { merge } from "lodash";
|
|
4
|
+
import { getJsExtensions, globToEntryPoints } from "../utils/index.js";
|
|
5
|
+
|
|
6
|
+
// Types
|
|
7
|
+
import type { PluginBuild, BuildOptions } from "esbuild";
|
|
8
|
+
import type { PluginOptions } from '../types/plugin-options.js';
|
|
9
|
+
|
|
10
|
+
export const setupEsmLib = async (build: PluginBuild, pluginOptions: PluginOptions) => {
|
|
11
|
+
|
|
12
|
+
pluginOptions.aliases ||= {};
|
|
13
|
+
pluginOptions.exclude ||= [];
|
|
14
|
+
|
|
15
|
+
const esbuildOptions: BuildOptions = {
|
|
16
|
+
bundle: false,
|
|
17
|
+
minify: false,
|
|
18
|
+
sourcemap: false,
|
|
19
|
+
splitting: true, // Works only on esm
|
|
20
|
+
loader: {
|
|
21
|
+
'.ts': 'ts',
|
|
22
|
+
'.mts': 'ts',
|
|
23
|
+
'.cts': 'ts',
|
|
24
|
+
'.tsx': 'ts',
|
|
25
|
+
'.mtsx': 'ts',
|
|
26
|
+
'.ctsx': 'ts',
|
|
27
|
+
'.mjs': 'ts',
|
|
28
|
+
'.cjs': 'ts',
|
|
29
|
+
'.js': 'ts',
|
|
30
|
+
},
|
|
31
|
+
target: [ "esnext" ],
|
|
32
|
+
platform: "browser",
|
|
33
|
+
// https://esbuild.github.io/api/#conditions
|
|
34
|
+
conditions: ['module','import'],
|
|
35
|
+
format: 'esm'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
merge(build.initialOptions, esbuildOptions);
|
|
39
|
+
|
|
40
|
+
build.initialOptions.entryPoints = await globToEntryPoints(build.initialOptions.entryPoints, pluginOptions.exclude);
|
|
41
|
+
|
|
42
|
+
await aliasPlugin(pluginOptions.aliases).setup(build);
|
|
43
|
+
await transformExtPlugin({ outExtension: getJsExtensions(pluginOptions.jsExtension) }).setup(build);
|
|
44
|
+
}
|
package/src/lib/index.ts
ADDED