Skip to content

Commit

Permalink
chore: use node 15
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Apr 14, 2021
1 parent e163824 commit 3671561
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 53 deletions.
27 changes: 15 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12
uses: actions/setup-node@v1
- name: Use Node.js 15
uses: actions/setup-node@v2-beta
with:
node-version: 12
node-version: 15
- name: Use npm 7
run: npm install -g npm@7
- name: Get npm cache directory
id: npm-cache
run: |
Expand Down Expand Up @@ -70,18 +72,17 @@ jobs:
runs-on: ubuntu-latest
needs: build
if: ${{ !startsWith(github.event.commits[0].message, 'chore(release)') }}
strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v2
- name: Fetch All
run: git fetch --prune --unshallow
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- name: Use Node.js 15
uses: actions/setup-node@v2-beta
with:
node-version: ${{ matrix.node-version }}
node-version: 15
- name: Use npm 7
run: npm install -g npm@7
- name: Install
run: |
npm ci
Expand Down Expand Up @@ -114,10 +115,12 @@ jobs:
needs: build
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12
uses: actions/setup-node@v1
- name: Use Node.js 15
uses: actions/setup-node@v2-beta
with:
node-version: 12
node-version: 15
- name: Use npm 7
run: npm install -g npm@7
- uses: actions/cache@v1
with:
path: ~/.npm
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12
uses: actions/setup-node@v1
- name: Use Node.js 15
uses: actions/setup-node@v2-beta
with:
node-version: 12
node-version: 15
- name: Use npm 7
run: npm install -g npm@7
- name: Install
run: |
npm ci
Expand Down
155 changes: 118 additions & 37 deletions scripts/plugins/rollup.typescript.plugin.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { existsSync } from "fs";
import { stat } from "fs-extra";
import { isAbsolute, posix, win32 } from "path";
import {
createSemanticDiagnosticsBuilderProgram,
createWatchCompilerHost,
createWatchProgram,
DiagnosticCategory,
formatDiagnosticsWithColorAndContext,
sys,
} from "typescript"
sys
} from "typescript";


function normalizePath(fileName) {
return fileName.split(win32.sep).join(posix.sep);
}
/**
* @param {number | void} timeout
*/
Expand Down Expand Up @@ -102,7 +109,7 @@ export class WatchProgramHelper {

/**
* Create a typecheck only typescript plugin
* @param {{tsconfig?: string[] tsconfigOverride?: import('typescript').CompilerOptions }} options
* @param {{tsconfig?: string[]; tsconfigOverride?: import('typescript').CompilerOptions }} options
* @returns {import('rollup').Plugin}
*/
const create = ({ tsconfig, tsconfigOverride } = {}) => {
Expand All @@ -121,6 +128,34 @@ const create = ({ tsconfig, tsconfigOverride } = {}) => {
getNewLine: () => sys.newLine,
}

// const configs = configPath.map((f) => {
// const { config, error } = readConfigFile(f, (p) => readFileSync(p, 'utf-8'))
// if (error) {
// throw error
// }
// return config || {}
// })

// function createModuleResolver(compilerOptions) {
// const cache = createModuleResolutionCache(
// process.cwd(),
// formatHost.getCanonicalFileName,
// compilerOptions
// );
// const moduleHost = { ...sys, ...formatHost };

// return (moduleName, containingFile) => {
// const resolved = nodeModuleNameResolver(
// moduleName,
// containingFile,
// compilerOptions,
// moduleHost,
// cache
// );
// return resolved.resolvedModule;
// };
// }

/**
* @type {import('typescript').WatchOfConfigFile<any>[]}
*/
Expand All @@ -133,30 +168,95 @@ const create = ({ tsconfig, tsconfigOverride } = {}) => {
*/
const diagnostics = []

// const resolvers = []

/**
* @type {import('rollup').Plugin}
*/
const plugin = {
name: "typescript:checker",
buildStart() {
if (!programs) {
programs = configPath.map((c) =>
createWatchProgram(
createWatchCompilerHost(
c,
tsconfigOverride || {
noEmit: true,
noEmitOnError: false,
},
sys,
createProgram,
(diagnostic) => {
diagnostics.push(diagnostic)
},
(diagnostic) => watcher.handleStatus(diagnostic)
)
programs = configPath.map((c, i) => {
// const options = Object.assign({}, c.compilerOptions, {
// noEmit: true,
// noEmitOnError: false,
// })
// console.log(options)
// const path = configPath[i]
const compilerHost = createWatchCompilerHost(
c,
tsconfigOverride || {
noEmit: true,
noEmitOnError: false,
},
sys,
createProgram,
(diagnostic) => {
diagnostics.push(diagnostic)
},
(diagnostic) => watcher.handleStatus(diagnostic)
)
// const resolveModule = createModuleResolver(options)
// compilerHost.resolveModuleNames = (names, containerFile) => names.map(name => resolveModule(name, containerFile))
// resolvers.push(resolveModule)
return createWatchProgram(compilerHost)
})
}
},
// async resolveId(importee, importer) {
// if (importee.endsWith('.ts')) {
// return
// }
// if (!importer) {
// const tsResult = await this.resolve(`${importee}.ts`, importer, {
// skipSelf: true,
// })
// if (tsResult) {
// return tsResult
// }
// return null
// }
// if (importee.startsWith('/@')) {
// console.log(`resolve id ${importee}`)
// return
// };

// // Convert path from windows separators to posix separators
// const containingFile = normalizePath(importer);

// for (const resolver of resolvers) {
// const resolved = resolver(importee, containingFile);

// if (resolved) {
// if (resolved.extension === '.d.ts') return null;
// return normalize(resolved.resolvedFileName);
// }
// }
// return null;
// },
async resolveId(id, importer) {
if (id.endsWith('.ts')) {
return
}
if (isAbsolute(id) && existsSync(id) && (await stat(id)).isFile()) {
return id
}
if (!id.endsWith('.json') && !id.endsWith('.js') && !id.endsWith('.js?commonjs-proxy')) {
const tsResult = await this.resolve(`${id}.ts`, importer, {
skipSelf: true,
})
if (tsResult) {
return tsResult
}
const indexTsResult = await this.resolve(
`${id}/index.ts`,
importer,
{ skipSelf: true }
)
if (indexTsResult) {
return indexTsResult
}
}
},
async load(id) {
Expand All @@ -165,25 +265,6 @@ const create = ({ tsconfig, tsconfigOverride } = {}) => {
}
await watcher.wait()
},
async resolveId(id, importer) {
if (id.endsWith(".ts")) {
return
}
const tsResult = await this.resolve(`${id}.ts`, importer, {
skipSelf: true,
})
if (tsResult) {
return tsResult
}
const indexTsResult = await this.resolve(
`${id}/index.ts`,
importer,
{ skipSelf: true }
)
if (indexTsResult) {
return indexTsResult
}
},
generateBundle() {
if (diagnostics.length > 0) {
const count = diagnostics.length
Expand Down
2 changes: 1 addition & 1 deletion scripts/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const config = [{
indent: ' ',
compact: false,
namedExports: true
})
}),
]
}]

Expand Down

0 comments on commit 3671561

Please sign in to comment.