@@ -50,40 +50,22 @@ const input = new Set([
5050] )
5151
5252const extensions = [ '.js' , '.jsx' , '.ts' , '.tsx' ]
53- const external = [
53+ const ESM_ONLY = new Set ( [ '@github/combobox-nav' , '@github/markdown-toolbar-element' , '@github/paste-markdown' ] )
54+ const dependencies = [
5455 ...Object . keys ( packageJson . peerDependencies ?? { } ) ,
5556 ...Object . keys ( packageJson . dependencies ?? { } ) ,
5657 ...Object . keys ( packageJson . devDependencies ?? { } )
5758]
58- function isExternal ( external ) {
59- return id => {
60- // Match on import paths that are the same as dependencies listed in
61- // `package.json`
62- const match = external . find ( pkg => {
63- return id === pkg
64- } )
65-
66- if ( match ) {
67- return true
68- }
6959
70- // In some cases, there may be a subpath import from a module which should
71- // also be treated as external. For example:
72- //
73- // External: @primer /behaviors
74- // Import: @primer /behaviors/utils
75- return external . some ( pkg => {
76- // Include the / to not match imports like: @primer /behaviors-for-acme/utils
77- return id . startsWith ( `${ pkg } /` )
78- } )
79- }
60+ function createPackageRegex ( name ) {
61+ return new RegExp ( `^${ name } (/.*)?` )
8062}
8163
8264const baseConfig = {
8365 input : Array . from ( input ) ,
8466 plugins : [
85- // Note: it's important that the babel plugin is ordered first for plugins
86- // like babel-plugin-preval to work as-intended
67+ // Note: it's important that the babel- plugin-preval is loaded first
68+ // to work as-intended
8769 babel ( {
8870 extensions,
8971 exclude : / n o d e _ m o d u l e s / ,
@@ -116,7 +98,9 @@ const baseConfig = {
11698 ]
11799 ]
118100 } ) ,
119- commonjs ( ) ,
101+ commonjs ( {
102+ extensions
103+ } ) ,
120104 resolve ( {
121105 extensions
122106 } )
@@ -127,7 +111,7 @@ export default [
127111 // ESM
128112 {
129113 ...baseConfig ,
130- external : isExternal ( external ) ,
114+ external : dependencies . map ( createPackageRegex ) ,
131115 output : {
132116 dir : 'lib-esm' ,
133117 format : 'esm' ,
@@ -139,7 +123,7 @@ export default [
139123 // CommonJS
140124 {
141125 ...baseConfig ,
142- external : isExternal ( external ) ,
126+ external : dependencies . filter ( name => ! ESM_ONLY . has ( name ) ) . map ( createPackageRegex ) ,
143127 output : {
144128 dir : 'lib' ,
145129 format : 'commonjs' ,
0 commit comments