makepack 1.7.14 → 1.7.15

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.
@@ -1,132 +1,132 @@
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 path from "path";
6
- import dts from "rollup-plugin-dts";
7
- import json from '@rollup/plugin-json';
8
- import terser from "@rollup/plugin-terser";
9
- import { loadRollupConfig, loadViteConfig } from "../../helpers.js";
10
-
11
- async function bundler(args, spinner) {
12
-
13
- const isTs = args.entry.endsWith('.ts') || args.entry.endsWith('.tsx')
14
- const viteConfig = await loadViteConfig()
15
- const rollupConfig = await loadRollupConfig()
16
- const viteRollupConfig = viteConfig?.build?.rollupOptions || {}
17
- Object.assign(rollupConfig || {}, viteRollupConfig);
18
-
19
- const config = {
20
- ...rollupConfig,
21
- input: [args.entry],
22
- external: (id) => {
23
- if (rollupConfig && typeof rollupConfig.external === 'function') {
24
- if (rollupConfig.external(id)) {
25
- return true;
26
- }
27
- } else if (Array.isArray(rollupConfig && rollupConfig.external)) {
28
- if (rollupConfig.external.includes(id)) {
29
- return true;
30
- }
31
- }
32
- return !id.startsWith('.') && !id.startsWith('/') && !/^[A-Za-z]:\\/.test(id);
33
- },
34
- plugins: [
35
- json(),
36
- resolve({
37
- extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.mjs', '.cjs'],
38
- browser: false
39
- }),
40
- commonjs(),
41
- typescript({
42
- tsconfig: false,
43
- target: "ES2017",
44
- module: "ESNext",
45
- jsx: "react-jsx",
46
- moduleResolution: "node", // ✅ Correct and lowercase
47
- esModuleInterop: true,
48
- skipLibCheck: false,
49
- strict: true,
50
- importHelpers: true,
51
- forceConsistentCasingInFileNames: true,
52
- declaration: false,
53
- emitDeclarationOnly: false,
54
- rootDir: path.resolve(process.cwd(), args.rootdir),
55
- }),
56
- args.minify ? terser() : null,
57
- ...rollupConfig?.plugins || [],
58
- ]
59
- };
60
-
61
- const bundle = await rollup(config);
62
- const esm = {
63
- dir: args.outdir,
64
- format: "esm",
65
- sourcemap: args.sourcemap,
66
- compact: true,
67
- strict: true,
68
- exports: "named"
69
- };
70
- if (!args.bundle) {
71
- esm.preserveModules = true
72
- esm.preserveModulesRoot = args.rootdir
73
- }
74
-
75
- let cjs = {
76
- ...esm,
77
- dir: args.outdir,
78
- format: "cjs",
79
- dynamicImportInCjs: true,
80
- esModule: true,
81
- }
82
-
83
- let outputOptions = []
84
-
85
- if (args.format === "both") {
86
- outputOptions = [
87
- { ...esm, entryFileNames: '[name].mjs' },
88
- cjs,
89
- ]
90
- } else if (args.format === "esm") {
91
- outputOptions = [esm];
92
- } else if (args.format === "cjs") {
93
- outputOptions = [cjs];
94
- } else if (args.format === "iife") {
95
- outputOptions = [{
96
- ...esm,
97
- format: "iife",
98
- name: args.name || path.basename(args.entry, path.extname(args.entry)),
99
- entryFileNames: '[name].js',
100
- }];
101
- } else if (args.format === "umd") {
102
- outputOptions = [{
103
- ...esm,
104
- format: "umd",
105
- name: args.name || path.basename(args.entry, path.extname(args.entry)),
106
- entryFileNames: '[name].js',
107
- }];
108
- }
109
-
110
- for (const output of outputOptions) {
111
- await bundle.write(output);
112
- }
113
- await bundle.close();
114
-
115
- // If TypeScript declaration files are requested, generate them
116
- if (isTs && args.declaration) {
117
- spinner.text = "Generating TypeScript declarations..."
118
- const bundlets = await rollup({
119
- ...config,
120
- plugins: [dts()],
121
- });
122
- await bundlets.write({
123
- format: "esm",
124
- preserveModules: true,
125
- preserveModulesRoot: args.rootdir,
126
- dir: path.join(args.outdir),
127
- });
128
- await bundlets.close();
129
- }
130
- }
131
-
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 path from "path";
6
+ import dts from "rollup-plugin-dts";
7
+ import json from '@rollup/plugin-json';
8
+ import terser from "@rollup/plugin-terser";
9
+ import { loadRollupConfig, loadViteConfig } from "../../helpers.js";
10
+
11
+ async function bundler(args, spinner) {
12
+
13
+ const isTs = args.entry.endsWith('.ts') || args.entry.endsWith('.tsx')
14
+ const viteConfig = await loadViteConfig()
15
+ const rollupConfig = await loadRollupConfig()
16
+ const viteRollupConfig = viteConfig?.build?.rollupOptions || {}
17
+ Object.assign(rollupConfig || {}, viteRollupConfig);
18
+
19
+ const config = {
20
+ ...rollupConfig,
21
+ input: [args.entry],
22
+ external: (id) => {
23
+ if (rollupConfig && typeof rollupConfig.external === 'function') {
24
+ if (rollupConfig.external(id)) {
25
+ return true;
26
+ }
27
+ } else if (Array.isArray(rollupConfig && rollupConfig.external)) {
28
+ if (rollupConfig.external.includes(id)) {
29
+ return true;
30
+ }
31
+ }
32
+ return !id.startsWith('.') && !id.startsWith('/') && !/^[A-Za-z]:\\/.test(id);
33
+ },
34
+ plugins: [
35
+ json(),
36
+ resolve({
37
+ extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.mjs', '.cjs'],
38
+ browser: false
39
+ }),
40
+ commonjs(),
41
+ typescript({
42
+ tsconfig: false,
43
+ target: "ES2017",
44
+ module: "ESNext",
45
+ jsx: "react-jsx",
46
+ moduleResolution: "node", // ✅ Correct and lowercase
47
+ esModuleInterop: true,
48
+ skipLibCheck: false,
49
+ strict: true,
50
+ importHelpers: true,
51
+ forceConsistentCasingInFileNames: true,
52
+ declaration: false,
53
+ emitDeclarationOnly: false,
54
+ rootDir: path.resolve(process.cwd(), args.rootdir),
55
+ }),
56
+ args.minify ? terser() : null,
57
+ ...rollupConfig?.plugins || [],
58
+ ]
59
+ };
60
+
61
+ const bundle = await rollup(config);
62
+ const esm = {
63
+ dir: args.outdir,
64
+ format: "esm",
65
+ sourcemap: args.sourcemap,
66
+ compact: true,
67
+ strict: true,
68
+ exports: "named"
69
+ };
70
+ if (!args.bundle) {
71
+ esm.preserveModules = true
72
+ esm.preserveModulesRoot = args.rootdir
73
+ }
74
+
75
+ let cjs = {
76
+ ...esm,
77
+ dir: args.outdir,
78
+ format: "cjs",
79
+ dynamicImportInCjs: true,
80
+ esModule: true,
81
+ }
82
+
83
+ let outputOptions = []
84
+
85
+ if (args.format === "both") {
86
+ outputOptions = [
87
+ { ...esm, entryFileNames: '[name].mjs' },
88
+ cjs,
89
+ ]
90
+ } else if (args.format === "esm") {
91
+ outputOptions = [esm];
92
+ } else if (args.format === "cjs") {
93
+ outputOptions = [cjs];
94
+ } else if (args.format === "iife") {
95
+ outputOptions = [{
96
+ ...esm,
97
+ format: "iife",
98
+ name: args.name || path.basename(args.entry, path.extname(args.entry)),
99
+ entryFileNames: '[name].js',
100
+ }];
101
+ } else if (args.format === "umd") {
102
+ outputOptions = [{
103
+ ...esm,
104
+ format: "umd",
105
+ name: args.name || path.basename(args.entry, path.extname(args.entry)),
106
+ entryFileNames: '[name].js',
107
+ }];
108
+ }
109
+
110
+ for (const output of outputOptions) {
111
+ await bundle.write(output);
112
+ }
113
+ await bundle.close();
114
+
115
+ // If TypeScript declaration files are requested, generate them
116
+ if (isTs && args.declaration) {
117
+ spinner.text = "Generating TypeScript declarations..."
118
+ const bundlets = await rollup({
119
+ ...config,
120
+ plugins: [dts()],
121
+ });
122
+ await bundlets.write({
123
+ format: "esm",
124
+ preserveModules: true,
125
+ preserveModulesRoot: args.rootdir,
126
+ dir: path.join(args.outdir),
127
+ });
128
+ await bundlets.close();
129
+ }
130
+ }
131
+
132
132
  export default bundler;
@@ -1,75 +1,75 @@
1
- import fs from 'fs-extra'
2
- import path from 'path'
3
- import ora from 'ora'
4
- import { concolor, logger } from '../../helpers.js'
5
- import bundler from './bundler.js'
6
-
7
- const build = async (args) => {
8
- /* args
9
- --format=both
10
- --bundle=true,
11
- --minify=false,
12
- --sourcemap=true,
13
- --declaration=true,
14
- */
15
-
16
- let printBool = (f) => typeof args[f] === 'string' ? (args[f] === 'true') : args[f];
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
-
39
- args = {
40
- format: args.format || "both",
41
- bundle: printBool('bundle'),
42
- minify: printBool('minify'),
43
- sourcemap: printBool('sourcemap'),
44
- declaration: printBool('declaration'),
45
- outdir,
46
- rootdir,
47
- entry: path.join(rootdir, entry),
48
- }
49
-
50
- if (fs.existsSync(outdir)) {
51
- fs.rmSync(outdir, { recursive: true, force: true });
52
- }
53
- fs.mkdirSync(outdir)
54
- const spinner = ora("✨ Bundling your package..\n").start();
55
- await bundler(args, spinner);
56
- spinner.text = "Copying package.json and readme.md files..."
57
- const pkgPath = path.join(process.cwd(), 'package.json');
58
- if (fs.existsSync(pkgPath)) {
59
- const pkgjson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
60
- delete pkgjson.scripts
61
- delete pkgjson.type
62
- fs.writeFileSync(path.join(outdir, 'package.json'), JSON.stringify(pkgjson, null, 2));
63
- } else {
64
- logger.error("package.json not found!");
65
- return;
66
- }
67
-
68
- fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(outdir, `/readme.md`))
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`)}`);
72
- spinner.stop();
73
- }
74
-
1
+ import fs from 'fs-extra'
2
+ import path from 'path'
3
+ import ora from 'ora'
4
+ import { concolor, logger } from '../../helpers.js'
5
+ import bundler from './bundler.js'
6
+
7
+ const build = async (args) => {
8
+ /* args
9
+ --format=both
10
+ --bundle=true,
11
+ --minify=false,
12
+ --sourcemap=true,
13
+ --declaration=true,
14
+ */
15
+
16
+ let printBool = (f) => typeof args[f] === 'string' ? (args[f] === 'true') : args[f];
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
+
39
+ args = {
40
+ format: args.format || "both",
41
+ bundle: printBool('bundle'),
42
+ minify: printBool('minify'),
43
+ sourcemap: printBool('sourcemap'),
44
+ declaration: printBool('declaration'),
45
+ outdir,
46
+ rootdir,
47
+ entry: path.join(rootdir, entry),
48
+ }
49
+
50
+ if (fs.existsSync(outdir)) {
51
+ fs.rmSync(outdir, { recursive: true, force: true });
52
+ }
53
+ fs.mkdirSync(outdir)
54
+ const spinner = ora("✨ Bundling your package..\n").start();
55
+ await bundler(args, spinner);
56
+ spinner.text = "Copying package.json and readme.md files..."
57
+ const pkgPath = path.join(process.cwd(), 'package.json');
58
+ if (fs.existsSync(pkgPath)) {
59
+ const pkgjson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
60
+ delete pkgjson.scripts
61
+ delete pkgjson.type
62
+ fs.writeFileSync(path.join(outdir, 'package.json'), JSON.stringify(pkgjson, null, 2));
63
+ } else {
64
+ logger.error("package.json not found!");
65
+ return;
66
+ }
67
+
68
+ fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(outdir, `/readme.md`))
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`)}`);
72
+ spinner.stop();
73
+ }
74
+
75
75
  export default build
@@ -1,10 +1,10 @@
1
-
2
- export default async () => {
3
- return {
4
- content: `
5
- node_modules
6
- .mpack
7
- `,
8
- filename: ".gitignore"
9
- }
1
+
2
+ export default async () => {
3
+ return {
4
+ content: `
5
+ node_modules
6
+ .mpack
7
+ `,
8
+ filename: ".gitignore"
9
+ }
10
10
  }
@@ -1,37 +1,37 @@
1
- export default async ({ template }) => {
2
-
3
- let ext = 'jsx'
4
- if (template === 'react with typescript') {
5
- ext = 'tsx'
6
- } else if (template === 'typescript') {
7
- ext = 'ts'
8
- }
9
- else if (template === 'javascript') {
10
- ext = 'js'
11
- }
12
-
13
- const content = `import React from 'react';
14
- import { createRoot } from 'react-dom/client';
15
- import ${ext.includes("sx") ? "Count" : "sum"} from './src/index.${ext}';
16
-
17
- const Main = () => {
18
- return (
19
- <div>
20
- <h1>Welcome to makepack CLI!</h1>
21
- <p>Edit <code>index.${ext}</code> and save to reload.</p>
22
- ${ext.includes("sx") ? "<Count />" : "<p>The sum is: {sum(5, 5)}</p>"}
23
- </div>
24
- );
25
- };
26
-
27
- const rootEle = document.getElementById('root')
28
- if (rootEle) {
29
- const root = createRoot(rootEle);
30
- root.render(<Main />);
31
- }
32
- `
33
- return {
34
- content,
35
- filename: `main.${ext.includes('ts') ? "tsx" : 'jsx'}`
36
- }
1
+ export default async ({ template }) => {
2
+
3
+ let ext = 'jsx'
4
+ if (template === 'react with typescript') {
5
+ ext = 'tsx'
6
+ } else if (template === 'typescript') {
7
+ ext = 'ts'
8
+ }
9
+ else if (template === 'javascript') {
10
+ ext = 'js'
11
+ }
12
+
13
+ const content = `import React from 'react';
14
+ import { createRoot } from 'react-dom/client';
15
+ import ${ext.includes("sx") ? "Count" : "sum"} from './src/index.${ext}';
16
+
17
+ const Main = () => {
18
+ return (
19
+ <div>
20
+ <h1>Welcome to makepack CLI!</h1>
21
+ <p>Edit <code>index.${ext}</code> and save to reload.</p>
22
+ ${ext.includes("sx") ? "<Count />" : "<p>The sum is: {sum(5, 5)}</p>"}
23
+ </div>
24
+ );
25
+ };
26
+
27
+ const rootEle = document.getElementById('root')
28
+ if (rootEle) {
29
+ const root = createRoot(rootEle);
30
+ root.render(<Main />);
31
+ }
32
+ `
33
+ return {
34
+ content,
35
+ filename: `main.${ext.includes('ts') ? "tsx" : 'jsx'}`
36
+ }
37
37
  }
@@ -1,50 +1,50 @@
1
-
2
- export default async (info) => {
3
- let dependencies = {}
4
- let devDependencies = {
5
- "makepack": "latest",
6
- "express": "latest"
7
- }
8
-
9
- if (info.template.includes("react")) {
10
- devDependencies["react"] = "^19.0.0"
11
- devDependencies["react-dom"] = "^19.0.0"
12
- }
13
-
14
- if (info.template.includes("typescript")) {
15
- devDependencies["typescript"] = "^4.4.2"
16
- devDependencies["@types/react"] = "^19.0.2"
17
- devDependencies["@types/react-dom"] = "^19.0.2"
18
- devDependencies["@types/express"] = "latest"
19
- }
20
-
21
- const json = {
22
- name: info.pdir,
23
- version: "1.0.0",
24
- main: `./index.js`,
25
- module: `./index.mjs`,
26
- types: `./index.d.ts`,
27
- description: "",
28
- keywords: [],
29
- sideEffects: false,
30
- scripts: {
31
- "start": "makepack start",
32
- "build": "makepack build",
33
- "release": "makepack release"
34
- },
35
- "exports": {
36
- ".": {
37
- "import": "./index.mjs",
38
- "require": "./index.js",
39
- "types": "./index.d.ts"
40
- }
41
- },
42
- dependencies,
43
- devDependencies
44
- }
45
-
46
- return {
47
- content: JSON.stringify(json, null, 3),
48
- filename: "package.json"
49
- }
1
+
2
+ export default async (info) => {
3
+ let dependencies = {}
4
+ let devDependencies = {
5
+ "makepack": "latest",
6
+ "express": "latest"
7
+ }
8
+
9
+ if (info.template.includes("react")) {
10
+ devDependencies["react"] = "^19.0.0"
11
+ devDependencies["react-dom"] = "^19.0.0"
12
+ }
13
+
14
+ if (info.template.includes("typescript")) {
15
+ devDependencies["typescript"] = "^4.4.2"
16
+ devDependencies["@types/react"] = "^19.0.2"
17
+ devDependencies["@types/react-dom"] = "^19.0.2"
18
+ devDependencies["@types/express"] = "latest"
19
+ }
20
+
21
+ const json = {
22
+ name: info.pdir,
23
+ version: "1.0.0",
24
+ main: `./index.js`,
25
+ module: `./index.mjs`,
26
+ types: `./index.d.ts`,
27
+ description: "",
28
+ keywords: [],
29
+ sideEffects: false,
30
+ scripts: {
31
+ "start": "makepack start",
32
+ "build": "makepack build",
33
+ "release": "makepack release"
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "import": "./index.mjs",
38
+ "require": "./index.js",
39
+ "types": "./index.d.ts"
40
+ }
41
+ },
42
+ dependencies,
43
+ devDependencies
44
+ }
45
+
46
+ return {
47
+ content: JSON.stringify(json, null, 3),
48
+ filename: "package.json"
49
+ }
50
50
  }
@@ -1,13 +1,13 @@
1
- export default async () => {
2
- const content = `
3
- function sum(a, b) {
4
- return a + b;
5
- }
6
-
7
- export default sum
8
- `
9
- return {
10
- content,
11
- filename: `src/index.js`
12
- }
1
+ export default async () => {
2
+ const content = `
3
+ function sum(a, b) {
4
+ return a + b;
5
+ }
6
+
7
+ export default sum
8
+ `
9
+ return {
10
+ content,
11
+ filename: `src/index.js`
12
+ }
13
13
  }