@hypernym/bundler 0.1.0 → 0.1.1
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/bin/index.mjs +10 -7
- package/package.json +1 -1
package/dist/bin/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import process, { stdout, cwd } from 'node:process';
|
|
3
3
|
import { createArgs } from '@hypernym/args';
|
|
4
|
-
import { readFile, stat } from 'node:fs/promises';
|
|
4
|
+
import { readFile, mkdir, writeFile, stat } from 'node:fs/promises';
|
|
5
5
|
import { resolve, parse } from 'node:path';
|
|
6
6
|
import { exists } from '@hypernym/utils/node';
|
|
7
7
|
import { dim, magenta, red, cyan, green } from '@hypernym/colors';
|
|
@@ -25,7 +25,7 @@ const externals = [
|
|
|
25
25
|
];
|
|
26
26
|
|
|
27
27
|
const name = "bundler";
|
|
28
|
-
const version = `0.1.
|
|
28
|
+
const version = `0.1.1`;
|
|
29
29
|
|
|
30
30
|
const cl = console.log;
|
|
31
31
|
const log = (...args) => {
|
|
@@ -96,7 +96,7 @@ function getOutputPath(outDir, input, types = false) {
|
|
|
96
96
|
return `./${output}`;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
async function loadConfig(filePath, defaults) {
|
|
99
|
+
async function loadConfig(cwd, filePath, defaults) {
|
|
100
100
|
const result = await build$1({
|
|
101
101
|
entryPoints: [filePath],
|
|
102
102
|
bundle: true,
|
|
@@ -106,8 +106,11 @@ async function loadConfig(filePath, defaults) {
|
|
|
106
106
|
packages: "external"
|
|
107
107
|
});
|
|
108
108
|
const code = result.outputFiles[0].text;
|
|
109
|
-
const
|
|
110
|
-
const
|
|
109
|
+
const tempDir = resolve(cwd, "node_modules", ".hypernym", "bundler");
|
|
110
|
+
const tempConfig = resolve(tempDir, "config.mjs");
|
|
111
|
+
await mkdir(tempDir, { recursive: true });
|
|
112
|
+
await writeFile(tempConfig, code, "utf-8");
|
|
113
|
+
const content = await import(tempConfig);
|
|
111
114
|
const config = {
|
|
112
115
|
...defaults,
|
|
113
116
|
...content.default
|
|
@@ -129,7 +132,7 @@ async function createConfigLoader(cwd, args) {
|
|
|
129
132
|
const path = resolve(cwd, args.config);
|
|
130
133
|
const isConfig = await exists(path);
|
|
131
134
|
if (isConfig)
|
|
132
|
-
return await loadConfig(path, defaults);
|
|
135
|
+
return await loadConfig(cwd, path, defaults);
|
|
133
136
|
else
|
|
134
137
|
return logger.exit(warnMessage);
|
|
135
138
|
}
|
|
@@ -139,7 +142,7 @@ async function createConfigLoader(cwd, args) {
|
|
|
139
142
|
const path = resolve(cwd, `${configName}${ext}`);
|
|
140
143
|
const isConfig = await exists(path);
|
|
141
144
|
if (isConfig)
|
|
142
|
-
return await loadConfig(path, defaults);
|
|
145
|
+
return await loadConfig(cwd, path, defaults);
|
|
143
146
|
}
|
|
144
147
|
return logger.exit(warnMessage);
|
|
145
148
|
}
|