Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update @actions/core #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions dist/index.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions dist/index.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */

/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
},
"devDependencies": {
"@types/concat-stream": "^1.6.0",
"@types/glob": "^7.1.1",
"@types/node": "^13.7.7",
"@types/yarnpkg__lockfile": "^1.1.3",
"hard-source-webpack-plugin": "^0.13.1",
"ts-loader": "^6.2.2",
"typescript": "^3.8.3",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11"
"@types/glob": "^7.1.3",
"@types/node": "^14.14.21",
"@types/webpack": "^4.41.26",
"@types/yarnpkg__lockfile": "^1.1.4",
"ts-loader": "^8.0.11",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"webpack": "^5.14.0",
"webpack-cli": "^4.3.1"
},
"dependencies": {
"@actions/core": "^1.2.3",
"@actions/core": "^1.2.6",
"@yarnpkg/lockfile": "^1.1.0",
"concat-stream": "^2.0.0",
"glob": "^7.1.6"
Expand Down
113 changes: 55 additions & 58 deletions src/langSvc/createHost.ts
Original file line number Diff line number Diff line change
@@ -1,107 +1,104 @@
import * as _ts from 'typescript'
import * as fs from 'fs'
import * as path from 'path'
import { FileEntry } from '../types'
import { libDTS } from '../gen/libDTS'
import * as _ts from 'typescript';
import * as fs from 'fs';
import * as path from 'path';
import { FileEntry } from '../types';
import { libDTS } from '../gen/libDTS';

const libDTSRegexp = /^lib\..*\.d\.ts$/
const libDTSRegexp = /^lib\..*\.d\.ts$/;

export const createHost = (fileNames: string[], compilerOptions: _ts.CompilerOptions, fileEntry: FileEntry, ts: typeof _ts): _ts.LanguageServiceHost => {
const getCurrentVersion = (fileName: string) => fileEntry.has(fileName) ? fileEntry.get(fileName)!.version : 0
const getTextFromSnapshot = (snapshot: _ts.IScriptSnapshot) => snapshot.getText(0, snapshot.getLength())
export const createHost = (
fileNames: string[],
compilerOptions: _ts.CompilerOptions,
fileEntry: FileEntry,
ts: typeof _ts
): _ts.LanguageServiceHost => {
const getCurrentVersion = (fileName: string) => (fileEntry.has(fileName) ? fileEntry.get(fileName)!.version : 0);
const getTextFromSnapshot = (snapshot: _ts.IScriptSnapshot) => snapshot.getText(0, snapshot.getLength());

const readFile = (fileName: string, encoding: string | undefined = 'utf8') => {
const readFile = (fileName: string, encoding: BufferEncoding = 'utf8') => {
if (libDTSRegexp.test(fileName)) {
return libDTS[fileName].content
return libDTS[fileName].content;
}

fileName = path.normalize(fileName);
try {
return fs.readFileSync(fileName, encoding);
return fs.readFileSync(fileName, encoding as 'utf8');
} catch (e) {
return undefined;
}
}
};

const readFileWithFallback = (
filePath: string,
encoding?: string | undefined
) => {
return ts.sys.readFile(filePath, encoding) || readFile(filePath, encoding)
}
const readFileWithFallback = (filePath: string, encoding?: BufferEncoding) => {
return ts.sys.readFile(filePath, encoding) || readFile(filePath, encoding);
};

const moduleResolutionHost: _ts.ModuleResolutionHost = {
fileExists: fileName => {
return ts.sys.fileExists(fileName) || readFile(fileName) !== undefined
fileExists: (fileName) => {
return ts.sys.fileExists(fileName) || readFile(fileName) !== undefined;
},
readFile: fileName => {
readFile: (fileName) => {
if (fileEntry.has(fileName)) {
const snapshot = fileEntry.get(fileName)!.scriptSnapshot
return getTextFromSnapshot(snapshot)
const snapshot = fileEntry.get(fileName)!.scriptSnapshot;
return getTextFromSnapshot(snapshot);
}
return readFileWithFallback(fileName)
return readFileWithFallback(fileName);
},
realpath: ts.sys.realpath,
directoryExists: ts.sys.directoryExists,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getDirectories: ts.sys.getDirectories
}
getDirectories: ts.sys.getDirectories,
};

const host: _ts.LanguageServiceHost = {
getScriptFileNames: () => fileNames,
getScriptVersion: fileName => getCurrentVersion(fileName) + '',
getScriptSnapshot: fileName => {
getScriptVersion: (fileName) => getCurrentVersion(fileName) + '',
getScriptSnapshot: (fileName) => {
if (fileEntry.has(fileName)) {
return fileEntry.get(fileName)!.scriptSnapshot
return fileEntry.get(fileName)!.scriptSnapshot;
} else {
const isLibDTS = libDTSRegexp.test(fileName)
const isLibDTS = libDTSRegexp.test(fileName);
if (!isLibDTS && !fs.existsSync(fileName)) {
return undefined
return undefined;
}
const content = isLibDTS ? libDTS[fileName].content : fs.readFileSync(fileName).toString()
const content = isLibDTS ? libDTS[fileName].content : fs.readFileSync(fileName).toString();

const scriptSnapshot = ts.ScriptSnapshot.fromString(content)
fileEntry.set(fileName, { version: 0, scriptSnapshot })
return scriptSnapshot
const scriptSnapshot = ts.ScriptSnapshot.fromString(content);
fileEntry.set(fileName, { version: 0, scriptSnapshot });
return scriptSnapshot;
}
},
getCurrentDirectory: () => process.cwd(),
getCompilationSettings: () => compilerOptions,
getDefaultLibFileName: options => ts.getDefaultLibFilePath(options),
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
resolveModuleNames: (moduleNames, containingFile, _, __, options) => {
const ret: (_ts.ResolvedModule | undefined)[] = moduleNames.map(name => {
if (/\.vue$/.test(name)) {
const resolved: _ts.ResolvedModule = {
resolvedFileName: normalize(path.resolve(path.dirname(containingFile), name))
}
return resolved
}
const ret: (_ts.ResolvedModule | undefined)[] = moduleNames.map((name) => {
if (/\.vue$/.test(name)) {
const resolved: _ts.ResolvedModule = {
resolvedFileName: normalize(path.resolve(path.dirname(containingFile), name)),
};
return resolved;
}

const { resolvedModule } = ts.resolveModuleName(
name,
containingFile,
options,
moduleResolutionHost
);
return resolvedModule
const { resolvedModule } = ts.resolveModuleName(name, containingFile, options, moduleResolutionHost);
return resolvedModule;
});
return ret;
},
fileExists: moduleResolutionHost.fileExists,
readFile: moduleResolutionHost.readFile,
readDirectory: ts.sys.readDirectory,
getDirectories: ts.sys.getDirectories,
realpath: moduleResolutionHost.realpath
}
realpath: moduleResolutionHost.realpath,
};

return host
}
return host;
};

// .ts suffix is needed since the compiler skips compile
// if the file name seems to be not supported types
function normalize (fileName: string): string {
function normalize(fileName: string): string {
if (/\.vue$/.test(fileName)) {
return fileName + '.ts'
return fileName + '.ts';
}
return fileName
return fileName;
}
29 changes: 0 additions & 29 deletions webpack.config.js

This file was deleted.

32 changes: 32 additions & 0 deletions webpack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import path from 'path';
import webpack from 'webpack';

module.exports = {
mode: 'production',
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.js',
},
target: 'node',
cache: {
type: 'filesystem',
buildDependencies: {
config: [__filename], // you may omit this when your CLI automatically adds it
},
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
} as webpack.Configuration;
Loading