makepack 1.6.10 → 1.7.0
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/package.json +12 -5
- package/src/actions/build/bundler.js +99 -0
- package/src/actions/build/index.js +33 -111
- package/src/actions/create/files/package-json.js +7 -23
- package/src/actions/start/index.js +7 -4
- package/src/helpers.js +0 -19
- package/src/index.js +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "makepack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
|
|
6
6
|
"files": [
|
|
@@ -30,17 +30,22 @@
|
|
|
30
30
|
"build": "node ./src/index.js build"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
33
|
+
"@rollup/plugin-commonjs": "^28.0.5",
|
|
34
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
35
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
36
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
34
37
|
"chokidar": "^4.0.3",
|
|
35
38
|
"commander": "^12.1.0",
|
|
36
39
|
"esbuild": "^0.25.5",
|
|
37
40
|
"express": "^4.21.1",
|
|
38
41
|
"fs-extra": "^11.2.0",
|
|
39
|
-
"glob": "^11.0.0",
|
|
40
42
|
"inquirer": "^12.1.0",
|
|
41
43
|
"lodash.debounce": "^4.0.8",
|
|
42
44
|
"madge": "^8.0.0",
|
|
43
45
|
"ora": "^8.1.1",
|
|
46
|
+
"rollup": "^4.43.0",
|
|
47
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
48
|
+
"tslib": "^2.8.1",
|
|
44
49
|
"vite": "^6.0.2"
|
|
45
50
|
},
|
|
46
51
|
"keywords": [
|
|
@@ -53,9 +58,11 @@
|
|
|
53
58
|
"npm-package"
|
|
54
59
|
],
|
|
55
60
|
"devDependencies": {
|
|
61
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
56
62
|
"@types/fs-extra": "^11.0.4",
|
|
57
|
-
"react": "^19.
|
|
63
|
+
"@types/react": "^19.1.8",
|
|
64
|
+
"react": "^19.1.0",
|
|
58
65
|
"react-dom": "^19.0.0",
|
|
59
|
-
"typescript": "^5.
|
|
66
|
+
"typescript": "^5.8.3"
|
|
60
67
|
}
|
|
61
68
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { rollup } from "rollup";
|
|
2
|
+
import resolve from "@rollup/plugin-node-resolve";
|
|
3
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
4
|
+
import typescript from "@rollup/plugin-typescript";
|
|
5
|
+
import { builtinModules } from "module";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import dts from "rollup-plugin-dts";
|
|
9
|
+
import json from '@rollup/plugin-json';
|
|
10
|
+
import terser from "@rollup/plugin-terser";
|
|
11
|
+
|
|
12
|
+
async function build(args, spinner) {
|
|
13
|
+
const pkg = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
|
|
14
|
+
const external = [
|
|
15
|
+
...builtinModules,
|
|
16
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
17
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
18
|
+
...Object.keys(pkg.peerDependencies ?? {}),
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const isTs = args.entry.endsWith(".ts")
|
|
22
|
+
|
|
23
|
+
const config = {
|
|
24
|
+
input: [args.entry],
|
|
25
|
+
external,
|
|
26
|
+
plugins: [
|
|
27
|
+
json(),
|
|
28
|
+
resolve(),
|
|
29
|
+
commonjs(),
|
|
30
|
+
isTs ? typescript({
|
|
31
|
+
compilerOptions: {
|
|
32
|
+
"module": "ESNext",
|
|
33
|
+
"jsx": "react",
|
|
34
|
+
"strict": true,
|
|
35
|
+
"forceConsistentCasingInFileNames": true,
|
|
36
|
+
"esModuleInterop": true
|
|
37
|
+
},
|
|
38
|
+
include: ["src/**/*.ts", "src/**/*.tsx"],
|
|
39
|
+
exclude: ["node_modules", ".mpack"],
|
|
40
|
+
}) : null,
|
|
41
|
+
args.minify ? terser() : null,
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const bundle = await rollup(config);
|
|
46
|
+
const esm = {
|
|
47
|
+
dir: args.outdir,
|
|
48
|
+
format: "esm",
|
|
49
|
+
sourcemap: args.sourcemap,
|
|
50
|
+
compact: true,
|
|
51
|
+
strict: true
|
|
52
|
+
};
|
|
53
|
+
if (!args.bundle) {
|
|
54
|
+
esm.preserveModules = true
|
|
55
|
+
esm.preserveModulesRoot = args.rootdir
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let cjs = {
|
|
59
|
+
...esm,
|
|
60
|
+
dir: args.outdir,
|
|
61
|
+
format: "cjs",
|
|
62
|
+
dynamicImportInCjs: true,
|
|
63
|
+
esModule: true,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let outputOptions = []
|
|
67
|
+
|
|
68
|
+
if (args.format === "both") {
|
|
69
|
+
outputOptions = [
|
|
70
|
+
{ ...esm, entryFileNames: '[name].mjs' },
|
|
71
|
+
cjs,
|
|
72
|
+
]
|
|
73
|
+
} else if (args.format === "esm") {
|
|
74
|
+
outputOptions = [esm];
|
|
75
|
+
} else if (args.format === "cjs") {
|
|
76
|
+
outputOptions = [cjs];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (const output of outputOptions) {
|
|
80
|
+
await bundle.write(output);
|
|
81
|
+
}
|
|
82
|
+
await bundle.close();
|
|
83
|
+
|
|
84
|
+
// If TypeScript declaration files are requested, generate them
|
|
85
|
+
if (isTs && args.declaration) {
|
|
86
|
+
spinner.text = "Generating TypeScript declarations..."
|
|
87
|
+
const bundlets = await rollup({
|
|
88
|
+
...config,
|
|
89
|
+
plugins: [dts()],
|
|
90
|
+
});
|
|
91
|
+
await bundlets.write({
|
|
92
|
+
...esm,
|
|
93
|
+
dir: path.join(args.outdir),
|
|
94
|
+
});
|
|
95
|
+
await bundlets.close();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default build;
|
|
@@ -1,136 +1,59 @@
|
|
|
1
|
-
import esbuild from 'esbuild'
|
|
2
1
|
import fs from 'fs-extra'
|
|
3
2
|
import path from 'path'
|
|
4
3
|
import ora from 'ora'
|
|
5
|
-
import { glob } from 'glob'
|
|
6
|
-
import ts from 'typescript'
|
|
7
4
|
import { concolor, logger } from '../../helpers.js'
|
|
8
|
-
|
|
9
|
-
const eBuild = async (conf) => {
|
|
10
|
-
|
|
11
|
-
await esbuild.build({
|
|
12
|
-
jsx: 'automatic',
|
|
13
|
-
...conf,
|
|
14
|
-
loader: {
|
|
15
|
-
'.ts': 'ts',
|
|
16
|
-
'.tsx': 'tsx'
|
|
17
|
-
},
|
|
18
|
-
outdir: path.join(process.cwd(), '.mpack', conf.format === 'esm' ? '' : conf.format),
|
|
19
|
-
})
|
|
20
|
-
}
|
|
5
|
+
import bundler from './bundler.js'
|
|
21
6
|
|
|
22
7
|
const build = async (args) => {
|
|
23
8
|
/* args
|
|
24
|
-
--format=
|
|
9
|
+
--format=both
|
|
25
10
|
--bundle=true,
|
|
26
11
|
--minify=false,
|
|
27
12
|
--sourcemap=true,
|
|
28
|
-
--
|
|
29
|
-
--target=es2020,
|
|
13
|
+
--declaration=true,
|
|
30
14
|
*/
|
|
31
15
|
|
|
32
|
-
|
|
33
16
|
let printBool = (f) => typeof args[f] === 'string' ? (args[f] === 'true') : args[f];
|
|
34
17
|
|
|
18
|
+
const outdir = path.join(process.cwd(), '.mpack');
|
|
19
|
+
const rootdir = path.join(process.cwd(), 'src');
|
|
20
|
+
|
|
21
|
+
let entry = '';
|
|
22
|
+
let entryts = path.join(rootdir, 'index.ts');
|
|
23
|
+
let entryjs = path.join(rootdir, 'index.js');
|
|
24
|
+
let entrytsx = path.join(rootdir, 'index.tsx');
|
|
25
|
+
let entryjsx = path.join(rootdir, 'index.jsx');
|
|
26
|
+
|
|
27
|
+
if (fs.existsSync(entryts)) {
|
|
28
|
+
entry = "index.ts";
|
|
29
|
+
} else if (fs.existsSync(entryjs)) {
|
|
30
|
+
entry = "index.js";
|
|
31
|
+
} else if (fs.existsSync(entrytsx)) {
|
|
32
|
+
entry = "index.tsx";
|
|
33
|
+
} else if (fs.existsSync(entryjsx)) {
|
|
34
|
+
entry = "index.jsx";
|
|
35
|
+
} else {
|
|
36
|
+
throw new Error("No entry file found in src directory. Please provide an index.ts or index.js file.");
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
args = {
|
|
36
|
-
format: args.format || "
|
|
40
|
+
format: args.format || "both",
|
|
37
41
|
bundle: printBool('bundle'),
|
|
38
42
|
minify: printBool('minify'),
|
|
39
43
|
sourcemap: printBool('sourcemap'),
|
|
40
|
-
platform: args.platform || "",
|
|
41
|
-
target: args.target || "es2020",
|
|
42
44
|
declaration: printBool('declaration'),
|
|
45
|
+
outdir,
|
|
46
|
+
rootdir,
|
|
47
|
+
entry: path.join(rootdir, entry),
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
const outdir = path.join(process.cwd(), '.mpack');
|
|
46
50
|
if (fs.existsSync(outdir)) {
|
|
47
51
|
fs.rmSync(outdir, { recursive: true, force: true });
|
|
48
52
|
}
|
|
49
53
|
fs.mkdirSync(outdir)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const files = await glob("src/**/*.{tsx,ts,js,jsx}") || [];
|
|
53
|
-
const entryPoints = files.map(entry => path.join(process.cwd(), entry));
|
|
54
|
-
let batchSize = args.format === 'default' ? 300 : 500;
|
|
55
|
-
|
|
56
|
-
let ebconfig = {
|
|
57
|
-
bundle: args.bundle,
|
|
58
|
-
minify: args.minify,
|
|
59
|
-
sourcemap: args.sourcemap,
|
|
60
|
-
platform: args.platform,
|
|
61
|
-
target: args.target,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
for (let i = 0; i < entryPoints.length; i += batchSize) {
|
|
65
|
-
const batch = entryPoints.slice(i, i + batchSize);
|
|
66
|
-
let config = {
|
|
67
|
-
...ebconfig,
|
|
68
|
-
entryPoints: batch,
|
|
69
|
-
}
|
|
70
|
-
if (args.format === 'default') {
|
|
71
|
-
await eBuild({ ...config, format: "esm" });
|
|
72
|
-
logger.success('ESM build generated successfully!');
|
|
73
|
-
await eBuild({ ...config, format: "cjs" });
|
|
74
|
-
logger.success('CJS build generated successfully!');
|
|
75
|
-
} else {
|
|
76
|
-
await eBuild({ ...config, format: args.format });
|
|
77
|
-
logger.success(`${args.format} build generated successfully!`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (args.declaration) {
|
|
83
|
-
const tsconfigPath = path.resolve(process.cwd(), "tsconfig.json");
|
|
84
|
-
let tsconfig = {};
|
|
85
|
-
if (fs.existsSync(tsconfigPath)) {
|
|
86
|
-
const parsedConfig = ts.getParsedCommandLineOfConfigFile(
|
|
87
|
-
tsconfigPath,
|
|
88
|
-
{},
|
|
89
|
-
ts.sys
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
if (!parsedConfig) {
|
|
93
|
-
logger.error("Error parsing tsconfig.json");
|
|
94
|
-
process.exit(1);
|
|
95
|
-
} else {
|
|
96
|
-
tsconfig = parsedConfig.options;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
tsconfig = {
|
|
101
|
-
allowJs: true,
|
|
102
|
-
target: ts.ScriptTarget.ESNext, // Ensure it's an enum
|
|
103
|
-
skipLibCheck: true,
|
|
104
|
-
moduleResolution: ts.ModuleResolutionKind.Node10,
|
|
105
|
-
...tsconfig, // Preserve root tsconfig settings
|
|
106
|
-
outDir: outdir,
|
|
107
|
-
declaration: true,
|
|
108
|
-
emitDeclarationOnly: true,
|
|
109
|
-
noEmit: false,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
spinner.text = "Generating TypeScript declarations..."
|
|
113
|
-
const program = ts.createProgram(files, tsconfig);
|
|
114
|
-
const emitResult = program.emit();
|
|
115
|
-
const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
116
|
-
|
|
117
|
-
if (diagnostics.length > 0) {
|
|
118
|
-
diagnostics.forEach(diagnostic => {
|
|
119
|
-
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
|
120
|
-
if (diagnostic.file) {
|
|
121
|
-
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
122
|
-
logger.error(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
|
123
|
-
} else {
|
|
124
|
-
logger.error(`${message}`);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
} else {
|
|
128
|
-
logger.success("TypeScript declaration files generated successfully!")
|
|
129
|
-
}
|
|
130
|
-
}
|
|
54
|
+
const spinner = ora("✨ Bundling your package..\n").start();
|
|
55
|
+
await bundler(args, spinner);
|
|
131
56
|
spinner.text = "Copying package.json and readme.md files..."
|
|
132
|
-
|
|
133
|
-
// update package.json to include the .mpack directory
|
|
134
57
|
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
135
58
|
if (fs.existsSync(pkgPath)) {
|
|
136
59
|
const pkgjson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
@@ -143,10 +66,9 @@ const build = async (args) => {
|
|
|
143
66
|
}
|
|
144
67
|
|
|
145
68
|
fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(outdir, `/readme.md`))
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
logger.info(`${concolor.yellow(`npm run release`)} or navigate to the ${concolor.yellow(`.mpack`)} directory and run ${concolor.yellow(`npm publish`)}`, 'RELEASE:', true)
|
|
69
|
+
spinner.succeed(concolor.bold(concolor.green(`Build successfully completed\n`)));
|
|
70
|
+
console.log(concolor.bold(`To publish your package to npm run:`));
|
|
71
|
+
console.log(`${concolor.yellow(`\`npm run release\``)} Or navigate to \`.mpack\` and run: ${concolor.yellow(`\`npm publish\`\n`)}`);
|
|
150
72
|
spinner.stop();
|
|
151
73
|
}
|
|
152
74
|
|
|
@@ -21,8 +21,8 @@ export default async (info) => {
|
|
|
21
21
|
const json = {
|
|
22
22
|
name: info.pdir,
|
|
23
23
|
version: "1.0.0",
|
|
24
|
-
main: `./
|
|
25
|
-
module: `./index.
|
|
24
|
+
main: `./index.js`,
|
|
25
|
+
module: `./index.mjs`,
|
|
26
26
|
types: `./index.d.ts`,
|
|
27
27
|
description: "",
|
|
28
28
|
keywords: [],
|
|
@@ -32,28 +32,12 @@ export default async (info) => {
|
|
|
32
32
|
"build": "makepack build",
|
|
33
33
|
"release": "makepack release"
|
|
34
34
|
},
|
|
35
|
-
exports: {
|
|
35
|
+
"exports": {
|
|
36
36
|
".": {
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"import": {
|
|
42
|
-
"types": "./index.d.ts",
|
|
43
|
-
"default": "./index.js"
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
"./*": {
|
|
47
|
-
"require": {
|
|
48
|
-
"types": "./*.d.ts",
|
|
49
|
-
"default": "./cjs/*.js"
|
|
50
|
-
},
|
|
51
|
-
"import": {
|
|
52
|
-
"types": "./*.d.ts",
|
|
53
|
-
"default": "./*.js"
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
"./cjs": null
|
|
37
|
+
"import": "./index.mjs",
|
|
38
|
+
"require": "./index.js",
|
|
39
|
+
"types": "./index.d.ts"
|
|
40
|
+
}
|
|
57
41
|
},
|
|
58
42
|
dependencies,
|
|
59
43
|
devDependencies
|
|
@@ -137,12 +137,15 @@ async function loadExp() {
|
|
|
137
137
|
|
|
138
138
|
async function getAllDependencies() {
|
|
139
139
|
try {
|
|
140
|
+
if (!expExists) {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
140
143
|
const result = await madge(uxpfile, { fileExtensions: ['ts', 'js'] });
|
|
141
144
|
const deps = Object.keys(result.obj());
|
|
142
|
-
const circular = await result.circular();
|
|
143
|
-
if (circular.length) {
|
|
144
|
-
|
|
145
|
-
}
|
|
145
|
+
// const circular = await result.circular();
|
|
146
|
+
// if (circular.length) {
|
|
147
|
+
// logger.warning(`Circular dependencies detected: ${circular.map(c => c.join(' -> ')).join(', ')}`);
|
|
148
|
+
// }
|
|
146
149
|
return deps.map(dep => path.resolve(path.dirname(uxpfile), dep));
|
|
147
150
|
} catch (err) {
|
|
148
151
|
logger.error(`Failed to analyze dependencies with madge: ${err.message || err}`);
|
package/src/helpers.js
CHANGED
|
@@ -19,34 +19,15 @@ export const conicon = {
|
|
|
19
19
|
success: '✔',
|
|
20
20
|
warning: '⚠',
|
|
21
21
|
error: '✖',
|
|
22
|
-
dot: '․',
|
|
23
|
-
pointer: '❯',
|
|
24
|
-
arrowRight: '→',
|
|
25
|
-
arrowDown: '↓',
|
|
26
|
-
arrowUp: '↑',
|
|
27
|
-
star: '★',
|
|
28
|
-
check: '✅',
|
|
29
|
-
cross: '❌',
|
|
30
|
-
question: '?',
|
|
31
|
-
ellipsis: '…',
|
|
32
|
-
clock: '⏱',
|
|
33
|
-
hourglass: '⏳',
|
|
34
|
-
rocket: '🚀',
|
|
35
|
-
bug: '🐞',
|
|
36
22
|
};
|
|
37
23
|
|
|
38
24
|
export const concolor = {
|
|
39
|
-
reset: (str) => `\x1b[0m${str}\x1b[0m`,
|
|
40
25
|
red: (str) => `\x1b[31m${str}\x1b[0m`,
|
|
41
26
|
green: (str) => `\x1b[32m${str}\x1b[0m`,
|
|
42
27
|
yellow: (str) => `\x1b[33m${str}\x1b[0m`,
|
|
43
28
|
blue: (str) => `\x1b[34m${str}\x1b[0m`,
|
|
44
|
-
magenta: (str) => `\x1b[35m${str}\x1b[0m`,
|
|
45
|
-
cyan: (str) => `\x1b[36m${str}\x1b[0m`,
|
|
46
|
-
white: (str) => `\x1b[37m${str}\x1b[0m`,
|
|
47
29
|
bold: (str) => `\x1b[1m${str}\x1b[0m`,
|
|
48
30
|
dim: (str) => `\x1b[2m${str}\x1b[0m`,
|
|
49
|
-
underline: (str) => `\x1b[4m${str}\x1b[0m`,
|
|
50
31
|
};
|
|
51
32
|
|
|
52
33
|
|
package/src/index.js
CHANGED
|
@@ -24,12 +24,10 @@ program
|
|
|
24
24
|
program
|
|
25
25
|
.command("build")
|
|
26
26
|
.description("Build the project")
|
|
27
|
-
.option("-f, --format <format>", "Output format (cjs, esm,
|
|
27
|
+
.option("-f, --format <format>", "Output format (cjs, esm, both)", "both")
|
|
28
28
|
.option("-b, --bundle <bundle>", "Bundle the project", false)
|
|
29
|
-
.option("-m, --minify <minify>", "Minify the output",
|
|
29
|
+
.option("-m, --minify <minify>", "Minify the output", false)
|
|
30
30
|
.option("-s, --sourcemap <sourcemap>", "Generate sourcemaps", true)
|
|
31
|
-
.option("-t, --target <target>", "Target ECMAScript version", "es2020")
|
|
32
|
-
.option("-p, --platform <platform>", "Platform to target (node, browser)", "")
|
|
33
31
|
.option("-d, --declaration <declaration>", "Generate TypeScript declaration files", true)
|
|
34
32
|
.action(build);
|
|
35
33
|
|