我正在使用GitLab CI进行项目,该过程的第一步是npm install.我node_modules稍后缓存以便更快地运行相同的作业,并将它们定义为构建工件,以便在后续阶段使用它们.但是,即使我缓存node_modules并且它是最新的,npm install每次install_packages运行作业时调用都需要很长时间,因为命令会遍历所有package.json并检查包的更新等(我假设).
根据某些条件,有没有办法只npm install在install_packages工作中运行?更具体地说(我认为这是最好的解决方案),package.json自上次构建以来是否已经改变了?
以下是我的.gitlab-ci.yml文件的相关部分:
image: node:6.9.1
stages:
- install
- prepare
- deploy
install_packages:
stage: install
script:
- npm prune
- npm install
cache:
key: ${CI_BUILD_REF_NAME}
paths:
- node_modules/
artifacts:
paths:
- node_modules/
only:
- master
- develop
build_and_test:
stage: prepare
script:
#do_stuff...
deploy_production:
stage: deploy
#do_stuff...
deploy_staging:
stage: deploy
#do_stuff...
Run Code Online (Sandbox Code Playgroud) 假设我有一个这样的对象:
const person = {
id: 87
name: 'Some Name',
address: {
street: 'Some street',
country: 'Some country'
}
}
Run Code Online (Sandbox Code Playgroud)
我想获得一个所有键值对的并集类型。所以类型应该是:
{ id: number } | { name: string } | { address: { street: string; country: string; } }
Run Code Online (Sandbox Code Playgroud)
那怎么办呢?我试过这个:
type PersonInfo = {
id: number;
name: string;
address: {
street: string;
country: string;
}
}
type PersonMap<M extends { [index: string]: any }> = {
[Key in keyof M]: M[Key]
};
type PersonTest1 = PersonMap<PersonInfo>[keyof PersonMap<PersonInfo>];
// Returns …Run Code Online (Sandbox Code Playgroud)