[READ-ONLY] Mirror of https://github.com/danielroe/siroc. Zero-config build tooling for Node
bundle node package rollup typescript
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: add initial support for using mkdist (#208)

authored by

Daniel Roe and committed by
GitHub
(Mar 8, 2021, 1:26 PM UTC) 1cd01278 5fb0c9f6

+153 -8
+31
README.md
··· 86 86 There are some conventions in place of configuration that are worth noting: 87 87 * the file type is inferred from the file name if possible (e.g. `babel.es.js` will be in 'es' format) 88 88 * `main` defaults to CJS, `module` to ES, `browser` to UMD, and `bin` to CJS 89 + * if you have a folder mapped using [subpath patterns](https://nodejs.org/api/packages.html#packages_subpath_patterns) and it matches a folder within your `src` folder, the files within will be copied across and lightly transpiled using [mkdist](https://github.com/unjsio/mkdist). 90 + 91 + ##### Example 92 + ```json5 93 + { 94 + "exports": { 95 + ".": { 96 + // This will be compiled in CJS and matched to src/index.ts 97 + "require": "./dist/index.js", 98 + // This will be compiled in ES and matched to src/index.ts 99 + "import": "./dist/index.es.js" 100 + }, 101 + // src/templates will be lightly transpiled with mkdist and copied to dist/templates 102 + "./templates/*": "./dist/templates/*", 103 + // siroc will not touch this 104 + "./package.json": "./package.json" 105 + }, 106 + // This will be compiled in CJS and matched to src/index.ts 107 + "main": "./dist/index.js", 108 + // This will be compiled in ES and matched to src/index.ts 109 + "module": "./dist/index.es.js", 110 + // Types will be generated for src/index.ts 111 + "types": "./dist/index.d.ts", 112 + "bin": { 113 + // This will be compiled in CJS and matched to src/cli/index.ts 114 + "siroc": "bin/cli.js", 115 + // This will be compiled in CJS and matched to src/cli/runtime.ts 116 + "siroc-runner": "bin/runtime.js" 117 + } 118 + } 119 + ``` 89 120 90 121 #### Build hooks 91 122
+1
package.json
··· 66 66 "fs-extra": "^9.1.0", 67 67 "glob": "^7.1.6", 68 68 "jiti": "^1.6.2", 69 + "mkdist": "^0.1.1", 69 70 "rollup": "^2.40.0", 70 71 "rollup-plugin-dts": "^2.0.1", 71 72 "rollup-plugin-esbuild": "2.6.1",
+56 -4
yarn.lock
··· 3661 3661 languageName: node 3662 3662 linkType: hard 3663 3663 3664 + "de-indent@npm:^1.0.2": 3665 + version: 1.0.2 3666 + resolution: "de-indent@npm:1.0.2" 3667 + checksum: a1933a4328d053d9b0db447668521a6d0360b509c115dc5340420fd645be556c00b82e491d6b862249981ed22fbf2016080b222ad23c25038aba72cb8e3120ea 3668 + languageName: node 3669 + linkType: hard 3670 + 3664 3671 "debug@npm:4, debug@npm:4.3.1, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.2.0": 3665 3672 version: 4.3.1 3666 3673 resolution: "debug@npm:4.3.1" ··· 4000 4007 languageName: node 4001 4008 linkType: hard 4002 4009 4003 - "esbuild@npm:^0.8.56": 4010 + "esbuild@npm:^0.8.32, esbuild@npm:^0.8.56": 4004 4011 version: 0.8.56 4005 4012 resolution: "esbuild@npm:0.8.56" 4006 4013 bin: ··· 4655 4662 languageName: node 4656 4663 linkType: hard 4657 4664 4658 - "fs-extra@npm:^9.1.0": 4665 + "fs-extra@npm:^9.0.1, fs-extra@npm:^9.1.0": 4659 4666 version: 9.1.0 4660 4667 resolution: "fs-extra@npm:9.1.0" 4661 4668 dependencies: ··· 4967 4974 languageName: node 4968 4975 linkType: hard 4969 4976 4970 - "globby@npm:11.0.2, globby@npm:^11.0.1": 4977 + "globby@npm:11.0.2, globby@npm:^11.0.1, globby@npm:^11.0.2": 4971 4978 version: 11.0.2 4972 4979 resolution: "globby@npm:11.0.2" 4973 4980 dependencies: ··· 5155 5162 dependencies: 5156 5163 function-bind: ^1.1.1 5157 5164 checksum: c686e15300d41364486c099a9259d9c418022c294244843dcd712c4c286ff839d4f23a25413baa28c4d2c1e828afc2aaab70f685400b391533980223c71fa1ca 5165 + languageName: node 5166 + linkType: hard 5167 + 5168 + "he@npm:^1.1.0": 5169 + version: 1.2.0 5170 + resolution: "he@npm:1.2.0" 5171 + bin: 5172 + he: bin/he 5173 + checksum: 212122003c20c8c17ac0c83a419b4c8e835411ff6ab9195d053ea6e4a0597cc005b5b8eabcbd57b0b0c0fe676f0049e09315845fff4e051198845491cbba260e 5158 5174 languageName: node 5159 5175 linkType: hard 5160 5176 ··· 6374 6390 languageName: node 6375 6391 linkType: hard 6376 6392 6377 - "jiti@npm:^1.6.2": 6393 + "jiti@npm:^1.2.0, jiti@npm:^1.6.2": 6378 6394 version: 1.6.2 6379 6395 resolution: "jiti@npm:1.6.2" 6380 6396 bin: ··· 7146 7162 languageName: node 7147 7163 linkType: hard 7148 7164 7165 + "mkdist@npm:^0.1.1": 7166 + version: 0.1.1 7167 + resolution: "mkdist@npm:0.1.1" 7168 + dependencies: 7169 + defu: ^3.2.2 7170 + esbuild: ^0.8.32 7171 + fs-extra: ^9.0.1 7172 + globby: ^11.0.2 7173 + jiti: ^1.2.0 7174 + mri: ^1.1.6 7175 + upath: ^2.0.1 7176 + vue-template-compiler: ^2.6.12 7177 + bin: 7178 + mkdist: dist/cli.js 7179 + checksum: dae3891b9da0036bbdd7f2343ab8389e81374c06095eac9d7b1fe70d79586e51f0a42282f583605931ca5973e749c5982cd77a6583a4e1eeda32c098d83b0776 7180 + languageName: node 7181 + linkType: hard 7182 + 7149 7183 "modify-values@npm:^1.0.0": 7150 7184 version: 1.0.1 7151 7185 resolution: "modify-values@npm:1.0.1" 7152 7186 checksum: 55165ae8b4ea2aafebe5027dd427d4a833d54606c81546f4d3c04943d99d194ac9481fa076719f326d243c475e2dfa5cf0219e68cffbbf9c44b24e46eb889779 7187 + languageName: node 7188 + linkType: hard 7189 + 7190 + "mri@npm:^1.1.6": 7191 + version: 1.1.6 7192 + resolution: "mri@npm:1.1.6" 7193 + checksum: 87a09465063063da6d69d98ac75a6206a597c7533561c74e8aab5e6490ebe2a0e94c583fb6e02429e1f4291286a9549eb6a9699c83f5bad252c2c9b4eada97da 7153 7194 languageName: node 7154 7195 linkType: hard 7155 7196 ··· 8880 8921 jest: ^26.6.3 8881 8922 jiti: ^1.6.2 8882 8923 lint-staged: ^10.5.4 8924 + mkdist: ^0.1.1 8883 8925 prettier: ^2.2.1 8884 8926 release-it: 14.4.1 8885 8927 rollup: ^2.40.0 ··· 10050 10092 core-util-is: 1.0.2 10051 10093 extsprintf: ^1.2.0 10052 10094 checksum: 38ea80312cb42e5e8b4ac562d108d675b2354a79f8f125d363671f692657461b9181fd26f4fc9acdca433f8afee099cb78058806e1303e6b15b8fb022affba94 10095 + languageName: node 10096 + linkType: hard 10097 + 10098 + "vue-template-compiler@npm:^2.6.12": 10099 + version: 2.6.12 10100 + resolution: "vue-template-compiler@npm:2.6.12" 10101 + dependencies: 10102 + de-indent: ^1.0.2 10103 + he: ^1.1.0 10104 + checksum: 5b05dda398cc1df7ba244316ddfb8f6463dbaafb4d23a4ac7e1cb8914e813a464f4ac055e41ac6e60feeadd4cccdeec1111fac592f2bb4eeb320889846a18912 10053 10105 languageName: node 10054 10106 linkType: hard 10055 10107
+18 -1
src/core/build/index.ts
··· 1 - import { dirname, join } from 'upath' 1 + import { dirname, join, relative } from 'upath' 2 2 3 3 import { bold, gray, green } from 'chalk' 4 4 import { remove, stat } from 'fs-extra' 5 + import { mkdist } from 'mkdist' 5 6 import { rollup, watch, RollupError } from 'rollup' 6 7 7 8 import type { BuildOptions, Package } from '../package' ··· 69 70 }) 70 71 71 72 logRollupConfig(pkg, rollupConfig) 73 + 74 + await runInParallel(pkg.folderExports, folder => { 75 + const { 1: distDir = folder } = folder.match(/^(.*[^*/])[*/]*$/) || [] 76 + const sourceFolder = pkg.resolveEntrypointFolder(distDir) 77 + if (!sourceFolder) return 78 + 79 + const srcDir = relative(pkg.options.rootDir, sourceFolder) 80 + pkg.logger.info( 81 + `Transpiling \`./${srcDir}\` to \`${distDir}\` with ${bold('mkdist')}.` 82 + ) 83 + mkdist({ 84 + srcDir, 85 + distDir: distDir.slice(2), 86 + rootDir: pkg.options.rootDir, 87 + }) 88 + }) 72 89 73 90 if (shouldWatch) { 74 91 // Watch
+33 -2
src/core/package/index.ts
··· 10 10 writeFile, 11 11 mkdirp, 12 12 chmod, 13 + pathExistsSync, 13 14 } from 'fs-extra' 14 15 import type { RollupOptions } from 'rollup' 15 16 import sortPackageJson from 'sort-package-json' ··· 30 31 RequireProperties, 31 32 } from '../utils' 32 33 import type { PackageJson } from './types' 33 - import { getEntrypointFilenames, getFlatValues } from './utils' 34 + import { 35 + getEntrypointFilenames, 36 + getEntrypointPaths, 37 + getFlatValues, 38 + } from './utils' 34 39 35 40 export interface DefaultPackageOptions { 36 41 /** ··· 396 401 `./${this.pkg.main}`, 397 402 `./${this.pkg.module}`, 398 403 `./${this.pkg.browser}`, 399 - ].includes(item) && !item.match(/[./]$/) 404 + ].includes(item) && !/[./*]$/.test(item) 405 + 406 + if (!exports) return [] 407 + if (typeof exports === 'string') return [exports].filter(filterExports) 408 + if (Array.isArray(exports)) return exports.filter(filterExports) 409 + 410 + return getFlatValues(exports).filter(filterExports) 411 + } 412 + 413 + get folderExports(): string[] { 414 + const { exports } = this.pkg 415 + 416 + const filterExports = (item: string) => /[a-z]\/\*$/.test(item) 400 417 401 418 if (!exports) return [] 402 419 if (typeof exports === 'string') return [exports].filter(filterExports) ··· 440 457 filenames.some(filename => { 441 458 input = this.resolvePath('src', filename) 442 459 return existsSync(input) 460 + }) 461 + 462 + return input 463 + } 464 + 465 + resolveEntrypointFolder(path = this.pkg.main) { 466 + if (!path) return undefined 467 + 468 + let input!: string 469 + const paths = getEntrypointPaths(path) 470 + 471 + paths.some(path => { 472 + input = this.resolvePath('src', path) 473 + return pathExistsSync(input) 443 474 }) 444 475 445 476 return input
+14 -1
src/core/package/utils.ts
··· 1 - import { basename, sep } from 'upath' 1 + import { sep } from 'upath' 2 2 import type { PackageJson } from './types' 3 3 4 4 const walkDownDirectory = (pathname: string) => { 5 5 const [first, ...rest] = pathname.split(sep) 6 6 return rest.join(sep) 7 + } 8 + 9 + export const getEntrypointPaths = (path: string) => { 10 + if (path.startsWith('./')) path = path.slice(2) 11 + 12 + const filenames = new Set<string>() 13 + let cwd = path 14 + do { 15 + filenames.add(cwd) 16 + cwd = walkDownDirectory(cwd) 17 + } while (cwd) 18 + 19 + return Array.from(filenames) 7 20 } 8 21 9 22 export const getEntrypointFilenames = (path: string) => {