makepack 1.3.7 → 1.3.9
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 +1 -1
- package/src/actions/create/files/package-json.js +17 -0
- package/src/actions/pack/index.js +46 -45
- package/src/actions/serve/index.js +12 -22
- package/src/helpers.js +57 -5
package/package.json
CHANGED
|
@@ -34,6 +34,23 @@ export default (args) => {
|
|
|
34
34
|
dependencies,
|
|
35
35
|
devDependencies,
|
|
36
36
|
keywords: [],
|
|
37
|
+
exports: {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./types/index.d.ts",
|
|
40
|
+
"import": "./esm/index.js",
|
|
41
|
+
"require": "./cjs/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./*": {
|
|
44
|
+
"types": "./types/*.d.ts",
|
|
45
|
+
"import": "./esm/*.js",
|
|
46
|
+
"require": "./cjs/*.js"
|
|
47
|
+
},
|
|
48
|
+
"./types/*": "./types/*.d.ts",
|
|
49
|
+
"./esm/*": "./esm/*.js",
|
|
50
|
+
"./esm/*.js": "./esm/*.js",
|
|
51
|
+
"./cjs/*": "./cjs/*.js",
|
|
52
|
+
"./cjs/*.js": "./cjs/*.js"
|
|
53
|
+
}
|
|
37
54
|
}
|
|
38
55
|
|
|
39
56
|
return {
|
|
@@ -15,60 +15,46 @@ const pack = async (args) => {
|
|
|
15
15
|
const files = await glob('src/**/*.{tsx,ts,js,jsx}') || []
|
|
16
16
|
const entryPoints = files.map(entry => path.join(process.cwd(), entry))
|
|
17
17
|
let loader = logLoader("Generating a production build for the package...")
|
|
18
|
-
const
|
|
18
|
+
const config = await loadConfig(args)
|
|
19
|
+
const packConfig = config.pack || {}
|
|
20
|
+
const esmConfig = packConfig?.esm
|
|
21
|
+
const cjsConfig = packConfig?.cjs
|
|
22
|
+
const tsConfig = packConfig?.tsconfig
|
|
19
23
|
|
|
20
24
|
async function build(format) {
|
|
21
25
|
return esbuild.buildSync({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// splitting: format === 'esm', // Enable code splitting only for ESM
|
|
25
|
-
minify: true,
|
|
26
|
-
sourcemap: true,
|
|
27
|
-
jsx: 'automatic',
|
|
28
|
-
loader: {
|
|
29
|
-
'.ts': 'ts',
|
|
30
|
-
'.tsx': 'tsx'
|
|
31
|
-
},
|
|
32
|
-
...esbuildConfig,
|
|
33
|
-
format: format, // 'esm' or 'cjs'
|
|
26
|
+
...(format === 'esm' ? esmConfig : cjsConfig),
|
|
27
|
+
format: format,
|
|
34
28
|
entryPoints,
|
|
35
29
|
outdir: path.join(process.cwd(), args.outdir, format),
|
|
36
30
|
});
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
await build('esm')
|
|
40
|
-
await build('cjs')
|
|
33
|
+
esmConfig && await build('esm')
|
|
34
|
+
cjsConfig && await build('cjs')
|
|
41
35
|
|
|
42
36
|
loader.stop()
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
console.error(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
|
64
|
-
} else {
|
|
65
|
-
console.error(`Error: ${message}`);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
console.log('✅ TypeScript declaration files generated successfully!');
|
|
37
|
+
if (tsConfig) {
|
|
38
|
+
loader = logLoader("🔄 Generating TypeScript declarations...")
|
|
39
|
+
const program = ts.createProgram(files, tsConfig);
|
|
40
|
+
const emitResult = program.emit();
|
|
41
|
+
const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
42
|
+
|
|
43
|
+
if (diagnostics.length > 0) {
|
|
44
|
+
diagnostics.forEach(diagnostic => {
|
|
45
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
|
46
|
+
if (diagnostic.file) {
|
|
47
|
+
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
48
|
+
console.error(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
|
49
|
+
} else {
|
|
50
|
+
console.error(`Error: ${message}`);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
console.log('✅ TypeScript declaration files generated successfully!');
|
|
55
|
+
}
|
|
56
|
+
loader.stop()
|
|
70
57
|
}
|
|
71
|
-
loader.stop()
|
|
72
58
|
|
|
73
59
|
let packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/package.json'), 'utf8'));
|
|
74
60
|
|
|
@@ -86,6 +72,23 @@ const pack = async (args) => {
|
|
|
86
72
|
main: './cjs/index.js',
|
|
87
73
|
module: './esm/index.js',
|
|
88
74
|
types: './types/index.d.ts',
|
|
75
|
+
exports: {
|
|
76
|
+
".": {
|
|
77
|
+
"types": "./types/index.d.ts",
|
|
78
|
+
"import": "./esm/index.js",
|
|
79
|
+
"require": "./cjs/index.js"
|
|
80
|
+
},
|
|
81
|
+
"./*": {
|
|
82
|
+
"types": "./types/*.d.ts",
|
|
83
|
+
"import": "./esm/*.js",
|
|
84
|
+
"require": "./cjs/*.js"
|
|
85
|
+
},
|
|
86
|
+
"./types/*": "./types/*.d.ts",
|
|
87
|
+
"./esm/*": "./esm/*.js",
|
|
88
|
+
"./esm/*.js": "./esm/*.js",
|
|
89
|
+
"./cjs/*": "./cjs/*.js",
|
|
90
|
+
"./cjs/*.js": "./cjs/*.js"
|
|
91
|
+
},
|
|
89
92
|
...packageJson,
|
|
90
93
|
}
|
|
91
94
|
|
|
@@ -104,8 +107,6 @@ const pack = async (args) => {
|
|
|
104
107
|
} else {
|
|
105
108
|
console.log(`To publish your package:\n1. Navigate to the ${args.outdir} directory:\ncd ./${args.outdir}\n2. Publish the package to npm:\nnpm publish\nYour package is ready to share with the world! 🚀`);
|
|
106
109
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
export default pack
|
|
@@ -7,7 +7,6 @@ import { glob } from 'glob'
|
|
|
7
7
|
import { logger, loadConfig } from '../../helpers.js'
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
import figlet from 'figlet';
|
|
10
|
-
import react from '@vitejs/plugin-react'
|
|
11
10
|
|
|
12
11
|
const app = express();
|
|
13
12
|
|
|
@@ -34,6 +33,7 @@ const serve = async (args) => {
|
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
36
|
+
|
|
37
37
|
let template = `
|
|
38
38
|
<!doctype html>
|
|
39
39
|
<html lang="en">
|
|
@@ -48,29 +48,19 @@ const serve = async (args) => {
|
|
|
48
48
|
</html>
|
|
49
49
|
`;
|
|
50
50
|
|
|
51
|
-
let
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
root: process.cwd(),
|
|
56
|
-
plugins: [react(), ...(viteConfig.plugins || [])],
|
|
57
|
-
server: {
|
|
58
|
-
middlewareMode: true,
|
|
59
|
-
...(viteConfig.server || {})
|
|
60
|
-
},
|
|
61
|
-
customLogger: {
|
|
62
|
-
info: (msg) => {
|
|
63
|
-
logger.info(msg)
|
|
64
|
-
},
|
|
65
|
-
warn: (msg) => logger.warning(msg),
|
|
66
|
-
error: (msg) => logger.error(msg),
|
|
67
|
-
...(viteConfig.customLogger || {})
|
|
68
|
-
},
|
|
69
|
-
appType: 'custom'
|
|
70
|
-
});
|
|
51
|
+
let config = await loadConfig(args)
|
|
52
|
+
let serveConfig = config.serve || {}
|
|
53
|
+
let viteConfig = serveConfig.vite || {}
|
|
54
|
+
let express = serveConfig.express
|
|
71
55
|
|
|
56
|
+
const vite = await createViteServer(viteConfig);
|
|
72
57
|
app.use(vite.middlewares);
|
|
73
|
-
|
|
58
|
+
|
|
59
|
+
if (express) {
|
|
60
|
+
express(app)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
app.get('*', async (req, res, next) => {
|
|
74
64
|
const url = req.originalUrl;
|
|
75
65
|
try {
|
|
76
66
|
template = await vite.transformIndexHtml(url, template);
|
package/src/helpers.js
CHANGED
|
@@ -4,6 +4,8 @@ import figures from 'figures';
|
|
|
4
4
|
import { pathToFileURL } from 'url';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import fs from 'fs-extra';
|
|
7
|
+
import react from '@vitejs/plugin-react'
|
|
8
|
+
import ts from 'typescript'
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
export const logLoader = (message = "") => {
|
|
@@ -58,13 +60,63 @@ export const logger = {
|
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
|
|
61
|
-
export const loadConfig = async (
|
|
62
|
-
const
|
|
63
|
-
|
|
63
|
+
export const loadConfig = async (args) => {
|
|
64
|
+
const makepack = path.resolve(process.cwd(), "makepack.js");
|
|
65
|
+
let esbuild = {
|
|
66
|
+
minify: true,
|
|
67
|
+
sourcemap: true,
|
|
68
|
+
jsx: 'automatic',
|
|
69
|
+
loader: {
|
|
70
|
+
'.ts': 'ts',
|
|
71
|
+
'.tsx': 'tsx'
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const defaultConfig = {
|
|
76
|
+
pack: {
|
|
77
|
+
tsconfig: {
|
|
78
|
+
declaration: true,
|
|
79
|
+
emitDeclarationOnly: true,
|
|
80
|
+
outDir: path.join(process.cwd(), args.outdir || "pack", 'types'),
|
|
81
|
+
strict: true,
|
|
82
|
+
allowJs: true,
|
|
83
|
+
jsx: ts.JsxEmit.React,
|
|
84
|
+
esModuleInterop: true,
|
|
85
|
+
},
|
|
86
|
+
esm: esbuild,
|
|
87
|
+
cjs: esbuild,
|
|
88
|
+
},
|
|
89
|
+
serve: {
|
|
90
|
+
express: () => { },
|
|
91
|
+
vite: {
|
|
92
|
+
root: process.cwd(),
|
|
93
|
+
plugins: [react()],
|
|
94
|
+
server: {
|
|
95
|
+
middlewareMode: true,
|
|
96
|
+
},
|
|
97
|
+
customLogger: {
|
|
98
|
+
info: (msg) => {
|
|
99
|
+
logger.info(msg)
|
|
100
|
+
},
|
|
101
|
+
warn: (msg) => logger.warning(msg),
|
|
102
|
+
error: (msg) => logger.error(msg),
|
|
103
|
+
},
|
|
104
|
+
appType: 'custom'
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (fs.existsSync(makepack)) {
|
|
64
110
|
try {
|
|
65
|
-
const c = await import(pathToFileURL(
|
|
66
|
-
|
|
111
|
+
const c = await import(pathToFileURL(makepack).href)
|
|
112
|
+
const configFn = c.default
|
|
113
|
+
if (typeof configFn === 'function') {
|
|
114
|
+
return configFn(defaultConfig)
|
|
115
|
+
}
|
|
67
116
|
} catch (error) {
|
|
117
|
+
console.log(error);
|
|
118
|
+
|
|
68
119
|
}
|
|
69
120
|
}
|
|
121
|
+
return defaultConfig
|
|
70
122
|
}
|