UNPKG

npmize

Version:

Let's create an npm package without worrying about anything.

59 lines (58 loc) 2.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const chokidar_1 = __importDefault(require("chokidar")); const tsc_1 = __importDefault(require("../scripts/tsc")); const fs_2 = require("../utils/fs"); const makeOutputFile_1 = __importDefault(require("../scripts/makeOutputFile")); const utils_1 = require("../utils"); function default_1(rootPath, options) { if (options.module) { return runDev(rootPath, options.tsConfig.outDir, options.module, options); } runDev(rootPath, options.tsConfig.outDir, 'cjs', options); runDev(rootPath, options.tsConfig.outDir, 'mjs', options); } function runDev(rootPath, shortOutDir, moduleType, options) { const tempOutDir = (0, utils_1.getNodeModulesTempDir)(rootPath, 'dev-' + moduleType); const finalOutDir = path_1.default.resolve(shortOutDir); (0, fs_2.cleanDir)(tempOutDir); (0, fs_2.cleanDir)(finalOutDir); function updateFile(filePath) { var _a, _b; return (0, makeOutputFile_1.default)(filePath, { useWorker: false, tempOutDir: tempOutDir, finalOutDir: finalOutDir, moduleType: moduleType, pushNodeCode: options.node, tsConfig: { baseUrl: (_a = options.tsConfig) === null || _a === void 0 ? void 0 : _a.baseUrl, paths: (_b = options.tsConfig) === null || _b === void 0 ? void 0 : _b.paths, }, }); } (0, tsc_1.default)(rootPath, [ ...options.tsc, '--outDir', tempOutDir, '--module', moduleType === 'cjs' ? 'commonjs' : 'esnext', '--watch', ], { async: true, stdio: moduleType === options.focus ? 'inherit' : 'ignore', }); chokidar_1.default.watch(tempOutDir).on('all', (_, filePath) => { if (!fs_1.default.existsSync(filePath)) return; if (!fs_1.default.statSync(filePath).isFile()) return; updateFile(filePath); }); }