Open manjusha888 opened 4 years ago
sed
command implementation is different on mac and linux. Examples were tested on linux.
You can replace those commands with separate node files.
switch-to-cjs.js
:
const replace = require('replace')
replace({
regex: '"target":\\s+"(.+?)"',
replacement: '"target": "es5"',
paths: ['packages/tsconfig.build.json'],
recursive: false,
silent: true
})
replace({
regex: '"module":\\s+"(.+?)"',
replacement: '"module": "commonjs"',
paths: ['packages/tsconfig.build.json'],
recursive: false,
silent: true
})
replace({
regex: '"outDir":\\s+"(.+?)"',
replacement: '"outDir": "lib/cjs"',
paths: ['packages'],
include: 'tsconfig.json',
recursive: true,
silent: true
})
switch-to-esm.js
const replace = require('replace')
replace({
regex: '"target":\\s+"(.+?)"',
replacement: '"target": "esnext"',
paths: ['packages/tsconfig.build.json'],
recursive: false,
silent: true
})
replace({
regex: '"module":\\s+"(.+?)"',
replacement: '"module": "esnext"',
paths: ['packages/tsconfig.build.json'],
recursive: false,
silent: true
})
replace({
regex: '"outDir":\\s+"(.+?)"',
replacement: '"outDir": "lib/esm"',
paths: ['packages'],
include: 'tsconfig.json',
recursive: true,
silent: true
})
and update package.json scripts:
"build": "yarn build:esm && yarn build:cjs && yarn module:esm",
"build:cjs": "yarn module:cjs && tsc -b",
"build:esm": "yarn module:esm && tsc -b",
"module:cjs": "node switch-to-cjs",
"module:esm": "node switch-to-esm",
when I cloned this project and ran 'yarn build' command , getting the following error:
sed -i -e '0,/target/{s:esnext:es5:}' -e '0,/module/{s:esnext:commonjs:}' ./tsconfig.json && sed -i -e s:lib/esm:lib/cjs: packages/**/tsconfig.json sed: 1: "0,/target/{s:esnext:es5:}": bad flag in substitute command: '}'