UNPKG

npmize

Version:

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

22 lines (21 loc) 891 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const varName = '_____VGhpcyBuYW1lIGlzIHVzZWQgdG8gZW5hYmxlIF9fZGlybmFtZSBhbmQgX19maWxlbmFtZSDwn5iK_____'; function default_1(fileContent) { const isFilenameExist = fileContent.includes('__filename'); const isDirnameExist = fileContent.includes('__dirname'); if (!isFilenameExist && !isDirnameExist) return ''; const nodeCodeContents = [ '/* START: AUTO-GENERATED CODE */', `import{fileURLToPath as ${varName}}from'url';`, ]; if (isFilenameExist) { nodeCodeContents.push(`var __filename=${varName}(import.meta.url);`); } if (isDirnameExist) { nodeCodeContents.push(`var __dirname=${varName}(new URL('.',import.meta.url));`); } return nodeCodeContents.join('\n') + '\n/* END: AUTO-GENERATED CODE */\n\n'; }