@4c/build
Advanced tools
Comparing version 2.3.2 to 3.0.0
@@ -6,2 +6,16 @@ # Change Log | ||
# [3.0.0](https://github.com/4Catalyzer/cli/compare/@4c/build@2.3.2...@4c/build@3.0.0) (2021-09-17) | ||
* feat!: convert to ESM (#318) ([5862163](https://github.com/4Catalyzer/cli/commit/58621632fc3961f3ed24eeddc4342645b8b5673b)), closes [#318](https://github.com/4Catalyzer/cli/issues/318) | ||
### BREAKING CHANGES | ||
* the codebase has migrated to native ESM which requires node 12+ and may cause issues downstream | ||
## [2.3.2](https://github.com/4Catalyzer/cli/compare/@4c/build@2.3.1...@4c/build@2.3.2) (2021-06-18) | ||
@@ -8,0 +22,0 @@ |
#!/usr/bin/env node | ||
require('@4c/cli-core/createCliFromCommand')(require('./command')); | ||
import createCliFromCommand from '@4c/cli-core/createCliFromCommand'; | ||
import * as Command from './command.js'; | ||
createCliFromCommand(Command); |
149
command.js
@@ -1,18 +0,22 @@ | ||
const path = require('path'); | ||
const { debuglog } = require('util'); | ||
import { createRequire } from 'module'; | ||
import { dirname, isAbsolute, join, resolve } from 'path'; | ||
import { debuglog } from 'util'; | ||
const { chalk, symbols, info } = require('@4c/cli-core/ConsoleUtilities'); | ||
const { getPackages } = require('@manypkg/get-packages'); | ||
const execa = require('execa'); | ||
const fs = require('fs-extra'); | ||
const Listr = require('listr'); | ||
import { chalk, info, symbols } from '@4c/cli-core/ConsoleUtilities'; | ||
import { getPackages } from '@manypkg/get-packages'; | ||
import execa from 'execa'; | ||
import fsExtra from 'fs-extra'; | ||
import Listr from 'listr'; | ||
const { copy, copyRest } = require('./copy'); | ||
import { copy, copyRest } from './copy.js'; | ||
const require = createRequire(import.meta.url); | ||
const debug = debuglog('@4c/build'); | ||
const { existsSync, readJson, readJsonSync } = fsExtra; | ||
function getCli(pkg, cmd) { | ||
const pkgPath = require.resolve(`${pkg}/package.json`); | ||
const { bin } = fs.readJsonSync(pkgPath); | ||
const loc = path.join(path.dirname(pkgPath), bin[cmd]); | ||
const { bin } = readJsonSync(pkgPath); | ||
const loc = join(dirname(pkgPath), bin[cmd]); | ||
@@ -22,57 +26,60 @@ return loc; | ||
exports.command = '$0 [patterns..]'; | ||
export const command = '$0 [patterns..]'; | ||
exports.describe = | ||
export const describe = | ||
'Compiles code via babel as well as Typescript type def files when appropriate.\n\n' + | ||
'Boolean flags can be negated by prefixing with --no-* (--foo, --no-foo)'; | ||
exports.builder = (_) => | ||
_.positional('patterns', { default: ['src'] }) | ||
.option('out-dir', { | ||
alias: 'd', | ||
type: 'string', | ||
}) | ||
.option('type-dir', { | ||
type: 'string', | ||
describe: | ||
'The location of any additional type defs, to be copied to the output folders', | ||
}) | ||
.option('esm', { | ||
type: 'boolean', | ||
default: undefined, | ||
describe: 'Builds an esm build', | ||
}) | ||
.option('extensions', { | ||
alias: 'x', | ||
default: ['.js', '.ts', '.tsx'], | ||
describe: 'The extensions of files to compile', | ||
}) | ||
.option('clean', { | ||
type: 'boolean', | ||
default: true, | ||
describe: 'Remove out directory before building', | ||
}) | ||
.option('tsconfig', { | ||
type: 'path', | ||
describe: 'The tsconfig.json location to use for type defs', | ||
}) | ||
.option('only-types', { | ||
type: 'boolean', | ||
describe: 'Compile only the type definitions', | ||
}) | ||
// off with `no-types` | ||
.option('types', { | ||
type: 'boolean', | ||
default: true, | ||
describe: 'Compile type defs', | ||
}) | ||
.option('copy-files', { | ||
type: 'boolean', | ||
default: true, | ||
describe: 'When compiling a directory copy over non-compilable files', | ||
}) | ||
// so we can pass anything after -- to babel | ||
.parserConfiguration({ | ||
'populate--': true, | ||
}); | ||
export function builder(_) { | ||
return ( | ||
_.positional('patterns', { default: ['src'] }) | ||
.option('out-dir', { | ||
alias: 'd', | ||
type: 'string', | ||
}) | ||
.option('type-dir', { | ||
type: 'string', | ||
describe: | ||
'The location of any additional type defs, to be copied to the output folders', | ||
}) | ||
.option('esm', { | ||
type: 'boolean', | ||
default: undefined, | ||
describe: 'Builds an esm build', | ||
}) | ||
.option('extensions', { | ||
alias: 'x', | ||
default: ['.js', '.ts', '.tsx'], | ||
describe: 'The extensions of files to compile', | ||
}) | ||
.option('clean', { | ||
type: 'boolean', | ||
default: true, | ||
describe: 'Remove out directory before building', | ||
}) | ||
.option('tsconfig', { | ||
type: 'path', | ||
describe: 'The tsconfig.json location to use for type defs', | ||
}) | ||
.option('only-types', { | ||
type: 'boolean', | ||
describe: 'Compile only the type definitions', | ||
}) | ||
// off with `no-types` | ||
.option('types', { | ||
type: 'boolean', | ||
default: true, | ||
describe: 'Compile type defs', | ||
}) | ||
.option('copy-files', { | ||
type: 'boolean', | ||
default: true, | ||
describe: 'When compiling a directory copy over non-compilable files', | ||
}) | ||
// so we can pass anything after -- to babel | ||
.parserConfiguration({ | ||
'populate--': true, | ||
}) | ||
); | ||
} | ||
@@ -94,3 +101,3 @@ function run(...args) { | ||
const safeToDelete = (dir, cwd = process.cwd()) => { | ||
const resolvedDir = path.isAbsolute(dir) ? dir : path.resolve(cwd, dir); | ||
const resolvedDir = isAbsolute(dir) ? dir : resolve(cwd, dir); | ||
@@ -101,8 +108,8 @@ return resolvedDir.startsWith(cwd) && resolvedDir !== cwd; | ||
const getTsconfig = () => { | ||
if (fs.existsSync('./tsconfig.build.json')) return './tsconfig.build.json'; | ||
if (fs.existsSync('./tsconfig.json')) return './tsconfig.json'; | ||
if (existsSync('./tsconfig.build.json')) return './tsconfig.build.json'; | ||
if (existsSync('./tsconfig.json')) return './tsconfig.json'; | ||
return null; | ||
}; | ||
exports.handler = async ({ | ||
export async function handler({ | ||
patterns, | ||
@@ -119,10 +126,10 @@ esm, | ||
...options | ||
}) => { | ||
}) { | ||
const { tool } = await getPackages(); | ||
const monorepo = tool !== 'root'; | ||
const pkg = await fs.readJson('package.json'); | ||
const pkg = await readJson('package.json'); | ||
const tsconfig = types && (options.tsconfig || getTsconfig()); | ||
const buildTypes = tsconfig && !!fs.existsSync(tsconfig); | ||
const buildTypes = tsconfig && !!existsSync(tsconfig); | ||
const tscCmd = buildTypes && getCli('typescript', 'tsc'); | ||
@@ -137,3 +144,3 @@ | ||
// eslint-disable-next-line no-param-reassign | ||
outDir = pkg.main && path.dirname(pkg.main); | ||
outDir = pkg.main && dirname(pkg.main); | ||
} | ||
@@ -146,3 +153,3 @@ | ||
if (esm !== false) { | ||
esmRoot = pkg.module && path.dirname(pkg.module); | ||
esmRoot = pkg.module && dirname(pkg.module); | ||
@@ -276,2 +283,2 @@ if (esm === true && !esmRoot) { | ||
} | ||
}; | ||
} |
14
copy.js
@@ -1,8 +0,7 @@ | ||
const path = require('path'); | ||
import { relative, resolve } from 'path'; | ||
const cpy = require('cpy'); | ||
const fs = require('fs-extra'); | ||
import cpy from 'cpy'; | ||
import fsExtra from 'fs-extra'; | ||
const relativeOut = (src, outDir) => | ||
path.relative(path.resolve(src), path.resolve(outDir)); | ||
const relativeOut = (src, outDir) => relative(resolve(src), resolve(outDir)); | ||
@@ -25,3 +24,4 @@ function copy(patterns, base, outDir) { | ||
// babel allows this, tho we don't usually specify file names in | ||
if (!fs.statSync(base).isDirectory()) { | ||
if (!fsExtra.statSync(base).isDirectory()) { | ||
return cpy([base, '!**/__tests__/**', '!**/__mocks__/**'], outDir); | ||
@@ -44,2 +44,2 @@ } | ||
module.exports = { copy, copyRest }; | ||
export { copy, copyRest }; |
{ | ||
"name": "@4c/build", | ||
"version": "2.3.2", | ||
"version": "3.0.0", | ||
"homepage": "https://github.com/4Catalyzer/cli/tree/master/packages/build", | ||
@@ -8,5 +8,11 @@ "bugs": { | ||
}, | ||
"type": "module", | ||
"license": "MIT", | ||
"author": "4Catalyzer", | ||
"main": "command.js", | ||
"exports": { | ||
".": "./command.js", | ||
"./command": "./command.js", | ||
"./copy": "./copy.js" | ||
}, | ||
"bin": { | ||
@@ -25,11 +31,11 @@ "build": "cli.js" | ||
"dependencies": { | ||
"@4c/cli-core": "^2.3.0", | ||
"@babel/cli": "^7.12.13", | ||
"@babel/core": "^7.12.13", | ||
"@4c/cli-core": "^3.0.0", | ||
"@babel/cli": "^7.15.4", | ||
"@babel/core": "^7.15.5", | ||
"@manypkg/get-packages": "^1.1.1", | ||
"cpy": "^8.1.1", | ||
"execa": "^5.0.0", | ||
"fs-extra": "^9.1.0", | ||
"cpy": "^8.1.2", | ||
"execa": "^5.1.1", | ||
"fs-extra": "^10.0.0", | ||
"listr": "^0.14.3", | ||
"typescript": "^4.1.3" | ||
"typescript": "^4.4.3" | ||
}, | ||
@@ -39,3 +45,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "a8c67ed5f2f76a381f5b221ea446a4b99a889eec" | ||
"gitHead": "39128f0407abab61238107e61c3b2d58ad920936" | ||
} |
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
17375
287
Yes
4
+ Added@4c/cli-core@3.0.0(transitive)
+ Addedansi-regex@6.0.1(transitive)
+ Addedarray-union@3.0.1(transitive)
+ Addedbl@5.1.0(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedchalk@5.3.0(transitive)
+ Addedci-info@3.9.0(transitive)
+ Addedcli-cursor@4.0.0(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedfs-extra@10.1.0(transitive)
+ Addedglobby@12.2.0(transitive)
+ Addedinquirer@8.2.6(transitive)
+ Addedis-ci@3.0.1(transitive)
+ Addedis-interactive@2.0.0(transitive)
+ Addedis-unicode-supported@1.3.0(transitive)
+ Addedlog-symbols@5.1.0(transitive)
+ Addedora@6.3.1(transitive)
+ Addedrestore-cursor@4.0.0(transitive)
+ Addedrxjs@7.8.1(transitive)
+ Addedslash@4.0.0(transitive)
+ Addedstdin-discarder@0.1.0(transitive)
+ Addedstrip-ansi@7.1.0(transitive)
+ Addedtslib@2.6.3(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)
- Removed@4c/cli-core@2.3.0(transitive)
- Removedat-least-node@1.0.0(transitive)
- Removedci-info@2.0.0(transitive)
- Removedcliui@7.0.4(transitive)
- Removedfs-extra@9.1.0(transitive)
- Removedinquirer@7.3.3(transitive)
- Removedis-ci@2.0.0(transitive)
- Removedyargs@16.2.0(transitive)
- Removedyargs-parser@20.2.9(transitive)
Updated@4c/cli-core@^3.0.0
Updated@babel/cli@^7.15.4
Updated@babel/core@^7.15.5
Updatedcpy@^8.1.2
Updatedexeca@^5.1.1
Updatedfs-extra@^10.0.0
Updatedtypescript@^4.4.3