
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
dumi babel exapple (base father2)
babel 方式是文件到文件的编译,不会做额外的处理
import Styles from 'style/index.css)为了支持 babel 方式下,引入静态资源,并生成 d.ts 声明文件,提了 PR,但 father2 目前官方没时间处理,我这里进行了 hack 处理。
临时方案:https://github.com/umijs/father/issues/227,以下不用看了
增加 npm 命令 "hack": "node scripts/hack-depend.js",对 node_modules 下的依赖进行 hack 处理:
typings.d.ts 文件中声明非 js/ts 模块:declare module '*.css';
declare module '*.less';
declare module '*.png';
declare module '*.jpg';
declare module '*.gif';
package.json 添加脚本命令:"scripts" : {
"postinstall": "node scripts/hack-depend.js"
}
scripts/hack-depend.js 脚本:/**
* 重写依赖模块(读取文件查找替换)
*/
const fs = require('fs');
const path = require('path');
const sep = path.posix.sep;
const hacks = [
{
// https://github.com/umijs/father/pull/220 ,官方没时间处理 PR,这里进行 hack 处理
name: 'father-build',
path: '../node_modules/father-build/lib/babel.js',
hack: data => {
// console.log(data)
return data
.replace(
`
function getTsconfigCompilerOptions(path) {
const config = parseTsconfig(path);
return config ? config.compilerOptions : undefined;
}
function getTSConfig() {
const tsconfigPath = (0, _path.join)(cwd, 'tsconfig.json');
const templateTsconfigPath = (0, _path.join)(__dirname, '../template/tsconfig.json');
if ((0, _fs.existsSync)(tsconfigPath)) {
return getTsconfigCompilerOptions(tsconfigPath) || {};
}
if (rootPath && (0, _fs.existsSync)((0, _path.join)(rootPath, 'tsconfig.json'))) {
return getTsconfigCompilerOptions((0, _path.join)(rootPath, 'tsconfig.json')) || {};
}
return getTsconfigCompilerOptions(templateTsconfigPath) || {};
}`,
`
function getTsconfigCompilerOptions(path) {
const config = parseTsconfig(path);
return config ? config.compilerOptions : undefined;
}
function getTsconfigInclude(path) {
const config = parseTsconfig(path);
const includesPath = config ? config.include || [] : [];
return includesPath;
}
function getTSConfig() {
const tsconfigPath = (0, _path.join)(cwd, 'tsconfig.json');
const templateTsconfigPath = (0, _path.join)(__dirname, '../template/tsconfig.json');
if ((0, _fs.existsSync)(tsconfigPath)) {
return getTsconfigCompilerOptions(tsconfigPath) || {};
}
if (rootPath && (0, _fs.existsSync)((0, _path.join)(rootPath, 'tsconfig.json'))) {
return getTsconfigCompilerOptions((0, _path.join)(rootPath, 'tsconfig.json')) || {};
}
return getTsconfigCompilerOptions(templateTsconfigPath) || {};
}
function getTSMatch() {
const tsconfigPath = join(cwd, 'tsconfig.json');
const templateTsconfigPath = join(__dirname, '../template/tsconfig.json');
if (existsSync(tsconfigPath)) {
return getTsconfigInclude(tsconfigPath) || [];
}
if (rootPath && existsSync(join(rootPath, 'tsconfig.json'))) {
return getTsconfigInclude(join(rootPath, 'tsconfig.json')) || [];
}
return getTsconfigInclude(templateTsconfigPath) || [];
}`,
)
.replace(
`&& !path.endsWith('.d.ts');`,
`&& (path.endsWith('typings.d.ts') || path.endsWith('index.d.ts') || !path.endsWith('.d.ts'));`,
)
.replace(
`[(0, _path.join)(srcPath, '**/*'),`,
`[(0, _path.join)(srcPath, '../typings.d.ts'),(0, _path.join)(srcPath, '../index.d.ts'),(0, _path.join)(srcPath, '../typings/index.d.ts'),(0, _path.join)(srcPath, '**/*'),`,
);
},
},
];
const run = () => {
for (const item of hacks) {
const finalPath = path.resolve(__dirname, item.path.replace(/\//g, sep));
fs.readFile(finalPath, 'utf8', (err, data) => {
if (err) {
throw err;
}
// console.log('=====data=====')
// console.log(data.indexOf(`&& !path.endsWith('.d.ts');`))
// console.log(typeof data)
// console.log(String(data))
// console.log('=====data=====')
const fixed = item.hack(data);
fixed &&
fs.writeFile(finalPath, fixed, err => {
if (err) {
throw err;
}
console.log('hack success');
});
});
}
};
run();
import React from 'react';
import { Foo, Button } from 'lean';
export default () => {
return (
<div>
<Foo title="demo" />
<Button btnType="primary">primary</Button>
</div>
);
};
Install dependencies,
$ npm i
Hack dependencies,
$ npm run hack
Start the dev server,
$ npm start
Build documentation,
$ npm run docs:build
Build library via father-build,
$ npm run build
Test Components,
# test all components
$ npm run test
# test all components with coverage
$ npm run test:coverage
# test one component Foo
$ npx umi-test src/Foo/index.test.tsx
FAQs
> dumi babel exapple (base father2)
We found that v5test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.