[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.

fix!: use regexps to match dependency externals (#213)

* avoids inlining subpaths or fully resolved paths

authored by

Daniel Roe and committed by
GitHub
(Jul 9, 2021, 12:36 PM +0100) 58de5dbf a9031cdf

+41 -4
+27 -1
src/core/build/rollup.spec.ts
··· 2 2 3 3 import { Package } from '../package' 4 4 import { builtins, builtinsMap } from './builtins' 5 - import { getRollupConfig } from './rollup' 5 + import { getRollupConfig, regexpForPackage } from './rollup' 6 6 import { getNameFunction } from './utils' 7 7 8 8 const getFixturePath = (path: string) => ··· 66 66 const newMap = builtinsMap() 67 67 expect(map).toBe(newMap) 68 68 expect(Object.values(map)[0]).toBe(true) 69 + }) 70 + }) 71 + 72 + describe('external matching', () => { 73 + const pattern = regexpForPackage('@nuxt/utils') 74 + 75 + it('should match package name', () => { 76 + expect(pattern.test('@nuxt/utils')).toBeTruthy() 77 + }) 78 + 79 + it('should match package subpath', () => { 80 + expect(pattern.test('@nuxt/utils/subpath')).toBeTruthy() 81 + }) 82 + 83 + it('should match fully resolved package path', () => { 84 + expect( 85 + pattern.test('/project/node_modules/@nuxt/utils/index.js') 86 + ).toBeTruthy() 87 + expect( 88 + pattern.test('c:\\project\\node_modules\\@nuxt\\utils\\index.js') 89 + ).toBeTruthy() 90 + }) 91 + 92 + it('should not match substring paths', () => { 93 + expect(pattern.test('@nuxt/utils2')).toBeFalsy() 94 + expect(pattern.test('a@nuxt/utils')).toBeFalsy() 69 95 }) 70 96 })
+14 -3
src/core/build/rollup.ts
··· 40 40 format: OutputOptions['format'] 41 41 } 42 42 43 + export function regexpForPackage(name: string) { 44 + // Should match `@foo/bar/index.js`, `node_modules\@foo\bar`, 45 + // `node_modules/@foo/bar` as well as `@foo/bar`. 46 + name = name.replace(/[\\/]/g, '[\\\\/]') 47 + return new RegExp(`(^|node_modules[\\\\/])${name}([\\\\/]|$)`, 'i') 48 + } 49 + 50 + function regexpForPackages(packages?: Record<string, string>) { 51 + return Object.keys(packages || {}).map(regexpForPackage) 52 + } 53 + 43 54 export function getRollupConfig( 44 55 { 45 56 input, ··· 74 85 75 86 const external = [ 76 87 // Dependencies that will be installed alongside the package 77 - ...Object.keys(pkgConfig.dependencies || {}), 78 - ...Object.keys(pkgConfig.optionalDependencies || {}), 79 - ...Object.keys(pkgConfig.peerDependencies || {}), 88 + ...regexpForPackages(pkgConfig.dependencies), 89 + ...regexpForPackages(pkgConfig.optionalDependencies), 90 + ...regexpForPackages(pkgConfig.peerDependencies), 80 91 // Builtin node modules 81 92 ...builtins, 82 93 ...externals,