From 8cfb47d17dc734b1262f978af151a156a8b983aa Mon Sep 17 00:00:00 2001 From: Nazmus Sayad <87106526+NazmusSayad@users.noreply.github.com> Date: Thu, 26 Sep 2024 19:32:37 +0600 Subject: [PATCH] minor import bug fixed --- package-lock.json | 4 ++-- package.json | 2 +- src/__lab__/index.ts | 5 ++--- src/program/dev.ts | 2 +- src/scripts/makeOutputFile.ts | 5 +++-- src/scripts/tsc.ts | 3 ++- src/scripts/tsconfig.ts | 8 ++++++-- 7 files changed, 17 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index b277f30..7e3f6ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "npmize", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "npmize", - "version": "1.1.0", + "version": "1.1.1", "license": "ISC", "dependencies": { "@babel/parser": "^7.25.6", diff --git a/package.json b/package.json index 631b499..5e178c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "npmize", - "version": "1.1.1", + "version": "1.1.2", "description": "Let's create an npm package without worrying about anything.", "bin": "./dist/index.js", "scripts": { diff --git a/src/__lab__/index.ts b/src/__lab__/index.ts index 80b5817..97c380f 100644 --- a/src/__lab__/index.ts +++ b/src/__lab__/index.ts @@ -1,9 +1,8 @@ console.clear() -const TEST_TARGET = '../npmize-test' +const TEST_TARGET = '../uni-run' import { app } from '../app' import '../main' // app.start(['init', TEST_TARGET]) -// app.start(['dev', TEST_TARGET]) +app.start(['dev', TEST_TARGET, '--node']) // app.start(['build', TEST_TARGET]) -app.start(['-v']) diff --git a/src/program/dev.ts b/src/program/dev.ts index 83a38cc..1ac8414 100644 --- a/src/program/dev.ts +++ b/src/program/dev.ts @@ -1,10 +1,10 @@ import fs from 'fs' import path from 'path' import tsc from '../scripts/tsc' +import { cleanDir } from '../utils/fs' import { CompileOptions } from './types.t' import makeOutput from '../scripts/makeOutputFile' import { getNodeModulesTempDir } from '../utils' -import { cleanDir } from '../utils/fs' export default function ( rootPath: string, diff --git a/src/scripts/makeOutputFile.ts b/src/scripts/makeOutputFile.ts index 512ca13..521f5de 100644 --- a/src/scripts/makeOutputFile.ts +++ b/src/scripts/makeOutputFile.ts @@ -29,8 +29,9 @@ export default function (filePath: string, options: MakeOutputOptions) { ) const contentWithNodeCode = - (true ? pushNodeCode(newFilePath, newFileContent) : newFileContent) + - newFileContent + options.pushNodeCode && options.moduleType === 'cjs' + ? pushNodeCode(newFilePath, newFileContent) + newFileContent + : newFileContent autoCreateDir(path.dirname(newFilePath)) fs.writeFileSync(newFilePath, contentWithNodeCode) diff --git a/src/scripts/tsc.ts b/src/scripts/tsc.ts index 4b4b8c8..9e15bde 100644 --- a/src/scripts/tsc.ts +++ b/src/scripts/tsc.ts @@ -8,7 +8,8 @@ export default function ( ) { const runner = options.async ? crossSpawn : crossSpawn.sync runner('npx', ['tsc', ...args], { - stdio: options.stdio || 'inherit', + // stdio: options.stdio || 'inherit', + stdio: 'ignore', cwd, }) } diff --git a/src/scripts/tsconfig.ts b/src/scripts/tsconfig.ts index f6e3c2b..0c74f9c 100644 --- a/src/scripts/tsconfig.ts +++ b/src/scripts/tsconfig.ts @@ -1,6 +1,6 @@ import * as fs from 'fs' import * as path from 'path' -import ts from 'typescript' +import ts, { ModuleKind } from 'typescript' export function findTSConfigPath(targetPath: string) { return ts.findConfigFile(targetPath, ts.sys.fileExists, 'tsconfig.json') @@ -110,8 +110,12 @@ export function resolveImportPath( importPath, baseUrl, { baseUrl, paths }, - moduleResolutionHost + moduleResolutionHost, + undefined, + undefined, + ModuleKind.CommonJS ) + if (resolved.resolvedModule?.packageId) return return resolved.resolvedModule?.resolvedFileName }