-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { createDebug, lodash, winPath } from '../' | ||
|
||
const debug = createDebug('xus:shared:BabelRegister') | ||
|
||
export class BabelRegister { | ||
only: Record<string, string[]> = {} | ||
|
||
setOnlyMap({ key, value }: { key: string; value: string[] }) { | ||
debug(`set ${key} of only map:`) | ||
debug(value) | ||
this.only[key] = value | ||
this.register() | ||
} | ||
|
||
register() { | ||
const only = lodash.uniq( | ||
Object.keys(this.only) | ||
.reduce<string[]>((memo, key) => { | ||
return memo.concat(this.only[key]) | ||
}, []) | ||
.map(winPath) | ||
) | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('@babel/register')({ | ||
presets: [ | ||
require.resolve('@xus/babel-preset'), | ||
{ | ||
targets: { node: 'current' }, | ||
useTransformRuntime: false, | ||
useTypescript: true | ||
} | ||
], | ||
ignore: [/node_modules/], | ||
only, | ||
extensions: ['.jsx', '.js', '.ts', '.tsx'], | ||
babelrc: false, | ||
cache: false | ||
}) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './getFileMeta' | ||
export * from './lookUpFile' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { existsSync, statSync, readFileSync } from 'fs' | ||
import { join, dirname } from 'path' | ||
|
||
export function lookUpFile( | ||
dir: string, | ||
formats: string[], | ||
pathOnly = false | ||
): string | undefined { | ||
for (const format of formats) { | ||
const fullPath = join(dir, format) | ||
if (existsSync(fullPath) && statSync(fullPath).isFile()) { | ||
return pathOnly ? fullPath : readFileSync(fullPath, 'utf-8') | ||
} | ||
} | ||
const parentDir = dirname(dir) | ||
if (parentDir !== dir) { | ||
return lookUpFile(parentDir, formats, pathOnly) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { lookUpFile } from '../file' | ||
|
||
export const getPkgName = (root: string) => { | ||
const { name } = JSON.parse(lookUpFile(root, ['package.json']) || `{}`) | ||
|
||
if (!name) throw new Error('no name found in package.json') | ||
|
||
return name.startsWith('@') ? name.split('/')[1] : name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './isLerna' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { existsSync } from 'fs' | ||
import { join } from 'path' | ||
|
||
export const isLernaPkg = (root: string) => { | ||
return existsSync(join(root, 'lerna.json')) | ||
} |