makepack 1.5.7 → 1.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "makepack",
3
- "version": "1.5.7",
3
+ "version": "1.5.9",
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": [
@@ -33,6 +33,7 @@
33
33
  "@vitejs/plugin-react": "^4.3.4",
34
34
  "chalk": "^5.4.1",
35
35
  "commander": "^12.1.0",
36
+ "cosmiconfig": "^9.0.0",
36
37
  "esbuild": "^0.24.2",
37
38
  "express": "^4.21.1",
38
39
  "figlet": "^1.8.0",
@@ -33,30 +33,30 @@ const build = async () => {
33
33
  }
34
34
 
35
35
  if (build.types) {
36
- const rootDir = process.cwd(); // Get the project root directory
37
- const tsconfigPath = path.join(rootDir, 'tsconfig.json');
38
-
36
+ const tsconfigPath = path.resolve(process.cwd(), "tsconfig.json");
39
37
  let tsconfig = {};
40
38
  if (fs.existsSync(tsconfigPath)) {
41
- console.log("✅ Found tsconfig.json, loading...");
42
- const rawConfig = fs.readFileSync(tsconfigPath, 'utf8');
43
- const parsedConfig = ts.parseConfigFileTextToJson(tsconfigPath, rawConfig);
44
- if (parsedConfig.error) {
45
- console.error("❌ Error parsing tsconfig.json:", parsedConfig.error);
39
+ const parsedConfig = ts.getParsedCommandLineOfConfigFile(
40
+ tsconfigPath,
41
+ {},
42
+ ts.sys
43
+ );
44
+
45
+ if (!parsedConfig) {
46
+ console.error("❌ Error parsing tsconfig.json");
47
+ process.exit(1);
46
48
  } else {
47
- tsconfig = parsedConfig.config.compilerOptions || {};
49
+ tsconfig = parsedConfig.options;
48
50
  }
49
- } else {
50
- console.log("⚠️ No tsconfig.json found, using default settings.");
51
51
  }
52
52
 
53
53
  tsconfig = {
54
54
  allowJs: true,
55
- target: ts.ScriptTarget.ESNext,
55
+ target: ts.ScriptTarget.ESNext, // Ensure it's an enum
56
56
  skipLibCheck: true,
57
57
  moduleResolution: ts.ModuleResolutionKind.Node10,
58
- ...tsconfig,
59
- outDir: path.join(rootDir, 'types'),
58
+ ...tsconfig, // Preserve root tsconfig settings
59
+ outDir: path.join(outdir, "types"),
60
60
  declaration: true,
61
61
  emitDeclarationOnly: true,
62
62
  noEmit: false,
@@ -11,6 +11,7 @@ const publish = async () => {
11
11
  logger.error(`Build directory ${buildDir} does not exist. Please build the project first`)
12
12
  process.exit(1)
13
13
  }
14
+
14
15
  logger.info(`Publishing the production build to the npm repository...`)
15
16
  execSync(`npm publish`, {
16
17
  cwd: buildDir
@@ -1,7 +1,8 @@
1
- import path from 'path'
2
- import fs from 'fs-extra'
1
+ import { cosmiconfig } from "cosmiconfig";
3
2
 
4
3
  const makepackConfig = async () => {
4
+ const explorer = cosmiconfig("makepack");
5
+ const configResult = await explorer.search();
5
6
 
6
7
  const defaultConfig = {
7
8
  build: {
@@ -41,22 +42,16 @@ const makepackConfig = async () => {
41
42
  express: (_app) => { }
42
43
  }
43
44
  }
44
- const configPath = path.resolve(process.cwd(), "makepack.js");
45
45
 
46
- if (fs.existsSync(configPath)) {
47
- try {
48
- const c = await import(`file://${configPath}`)
49
- const configFn = c.default
50
- if (typeof configFn === 'function') {
51
- const nc = configFn(defaultConfig)
52
- if (!nc) {
53
- console.log("Config function must return a config object")
54
- process.exit(1)
55
- }
56
- return nc
46
+ if (configResult && configResult.config) {
47
+ let fn = configResult.config;
48
+ if (typeof fn === 'function') {
49
+ const userConfig = fn(defaultConfig)
50
+ if (!userConfig) {
51
+ console.log("Config function must return a config object")
52
+ process.exit(1)
57
53
  }
58
- } catch (error) {
59
- console.log(error);
54
+ return userConfig
60
55
  }
61
56
  }
62
57
  return defaultConfig