| 50 | } |
| 51 | |
| 52 | function writePackageExportShim(file) { |
| 53 | let extension = path.extname(file); |
| 54 | |
| 55 | // webpack 4 does not support importing non-ESM modules from .mjs files, so most packages use |
| 56 | // the generated .js variant. S2 is built directly to .mjs and only needs the Icon shim. |
| 57 | let shim = file.replace('/dist/exports/', '/'); |
| 58 | let specifier = path.relative(shim, file); |
| 59 | |
| 60 | let dir = shim.slice(0, -extension.length); |
| 61 | fs.mkdirSync(dir, {recursive: true}); |
| 62 | fs.writeFileSync( |
| 63 | dir + '/package.json', |
| 64 | JSON.stringify( |
| 65 | { |
| 66 | main: specifier.slice(0, -extension.length) + '.cjs', |
| 67 | module: specifier, |
| 68 | types: path.relative( |
| 69 | shim, |
| 70 | file.replace('/dist/exports/', '/dist/types/exports/').slice(0, -extension.length) + |
| 71 | '.d.ts' |
| 72 | ) |
| 73 | }, |
| 74 | null, |
| 75 | 2 |
| 76 | ) + '\n' |
| 77 | ); |
| 78 | } |