@wessberg/rollup-plugin-ts
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -0,1 +1,10 @@ | ||
<a name="0.0.8"></a> | ||
## <small>0.0.8 (2018-04-04)</small> | ||
* 0.0.8 ([c4e2318](https://github.com/wessberg/rollup-plugin-ts/commit/c4e2318)) | ||
* Added an option to also parse external modules ([6d08ab3](https://github.com/wessberg/rollup-plugin-ts/commit/6d08ab3)) | ||
* Bumped version ([cbac7b1](https://github.com/wessberg/rollup-plugin-ts/commit/cbac7b1)) | ||
<a name="0.0.7"></a> | ||
@@ -2,0 +11,0 @@ ## <small>0.0.7 (2018-03-31)</small> |
@@ -7,2 +7,3 @@ export interface ITypescriptPluginOptions { | ||
exclude: string | string[]; | ||
parseExternalModules: boolean; | ||
} |
@@ -7,2 +7,2 @@ import { Plugin } from "rollup"; | ||
*/ | ||
export default function typescriptRollupPlugin({root, tsconfig, noEmit, include, exclude}?: Partial<ITypescriptPluginOptions>): Plugin; | ||
export default function typescriptRollupPlugin({root, tsconfig, noEmit, include, exclude, parseExternalModules}?: Partial<ITypescriptPluginOptions>): Plugin; |
@@ -18,3 +18,3 @@ "use strict"; | ||
*/ | ||
function typescriptRollupPlugin({ root = process.cwd(), tsconfig = "tsconfig.json", noEmit = false, include = [], exclude = [] } = {}) { | ||
function typescriptRollupPlugin({ root = process.cwd(), tsconfig = "tsconfig.json", noEmit = false, include = [], exclude = [], parseExternalModules = false } = {}) { | ||
/** | ||
@@ -124,3 +124,3 @@ * The CompilerOptions to use with Typescript for individual files | ||
if (languageServiceHost == null) { | ||
languageServiceHost = new typescript_language_service_host_1.TypescriptLanguageServiceHost(root, typescriptOptions); | ||
languageServiceHost = new typescript_language_service_host_1.TypescriptLanguageServiceHost(root, parseExternalModules, typescriptOptions); | ||
formatHost = new format_host_1.FormatHost(languageServiceHost, root); | ||
@@ -127,0 +127,0 @@ } |
@@ -0,4 +1,4 @@ | ||
import { CompilerOptions, Diagnostic, IScriptSnapshot, LanguageService, ParsedCommandLine } from "typescript"; | ||
import { ITypescriptLanguageServiceEmitResult } from "./i-typescript-language-service-emit-result"; | ||
import { ITypescriptLanguageServiceFileBase } from "./i-typescript-language-service-file"; | ||
import { LanguageService, ParsedCommandLine, CompilerOptions, IScriptSnapshot, Diagnostic } from "typescript"; | ||
import { ITypescriptLanguageServiceHost } from "./i-typescript-language-service-host"; | ||
@@ -10,4 +10,10 @@ /** | ||
private readonly appRoot; | ||
private readonly parseExternalModules; | ||
private typescriptOptions; | ||
/** | ||
* The part of a path that matches external modules | ||
* @type {string} | ||
*/ | ||
private static readonly EXTERNAL_MODULES_PATH; | ||
/** | ||
* The LanguageService host to use. Will be equal to this instance | ||
@@ -22,3 +28,3 @@ * @type {LanguageService} | ||
private readonly files; | ||
constructor(appRoot: string, typescriptOptions: ParsedCommandLine); | ||
constructor(appRoot: string, parseExternalModules: boolean, typescriptOptions: ParsedCommandLine); | ||
/** | ||
@@ -61,8 +67,2 @@ * Gets the CompilerOptions | ||
/** | ||
* Gets the Script text for the given file name | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
getScriptText(fileName: string): string; | ||
/** | ||
* Gets a Script Snapshot for the given file name | ||
@@ -72,3 +72,3 @@ * @param {string} fileName | ||
*/ | ||
getScriptSnapshot(fileName: string): IScriptSnapshot; | ||
getScriptSnapshot(fileName: string): IScriptSnapshot | undefined; | ||
/** | ||
@@ -145,2 +145,20 @@ * Gets the text of all files | ||
emit(fileName: string, onlyDeclarations?: boolean): ITypescriptLanguageServiceEmitResult[]; | ||
/** | ||
* Returns true if the given path is qualified | ||
* @param {string} path | ||
* @returns {boolean} | ||
*/ | ||
private pathIsQualified(path); | ||
/** | ||
* Normalizes the given file name | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
private normalizeFilename(fileName); | ||
/** | ||
* Ensure that the given file name is in fact absolute | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
private makeAbsolute(fileName); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs_1 = require("fs"); | ||
const path_1 = require("path"); | ||
const typescript_1 = require("typescript"); | ||
const constants_1 = require("./constants"); | ||
const helpers_1 = require("./helpers"); | ||
const i_typescript_language_service_emit_result_1 = require("./i-typescript-language-service-emit-result"); | ||
const typescript_1 = require("typescript"); | ||
const constants_1 = require("./constants"); | ||
/** | ||
@@ -11,4 +13,5 @@ * A LanguageServiceHost for Typescript | ||
class TypescriptLanguageServiceHost { | ||
constructor(appRoot, typescriptOptions) { | ||
constructor(appRoot, parseExternalModules, typescriptOptions) { | ||
this.appRoot = appRoot; | ||
this.parseExternalModules = parseExternalModules; | ||
this.typescriptOptions = typescriptOptions; | ||
@@ -56,5 +59,11 @@ /** | ||
addFile(file) { | ||
const existing = this.files.get(file.fileName); | ||
const version = existing != null ? `${parseInt(existing.version) + 1}` : "1"; | ||
this.files.set(file.fileName, Object.assign({}, file, { file: typescript_1.ScriptSnapshot.fromString(file.text), version })); | ||
const normalizedFilename = this.normalizeFilename(file.fileName); | ||
const existing = this.files.get(normalizedFilename); | ||
this.files.set(normalizedFilename, { | ||
fileName: normalizedFilename, | ||
text: file.text, | ||
isMainEntry: file.isMainEntry, | ||
file: typescript_1.ScriptSnapshot.fromString(file.text), | ||
version: existing != null ? `${parseInt(existing.version) + 1}` : "1" | ||
}); | ||
} | ||
@@ -66,3 +75,4 @@ /** | ||
removeFile(fileName) { | ||
this.files.delete(fileName); | ||
const normalizedFilename = this.normalizeFilename(fileName); | ||
this.files.delete(normalizedFilename); | ||
} | ||
@@ -86,11 +96,2 @@ /** | ||
/** | ||
* Gets the Script text for the given file name | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
getScriptText(fileName) { | ||
const file = this.files.get(fileName); | ||
return file == null ? "" : file.text; | ||
} | ||
/** | ||
* Gets a Script Snapshot for the given file name | ||
@@ -101,3 +102,12 @@ * @param {string} fileName | ||
getScriptSnapshot(fileName) { | ||
return typescript_1.ScriptSnapshot.fromString(this.getScriptText(fileName)); | ||
const normalizedFilename = this.normalizeFilename(fileName); | ||
const absolute = this.makeAbsolute(normalizedFilename); | ||
if (this.files.has(normalizedFilename)) { | ||
return this.files.get(normalizedFilename).file; | ||
} | ||
if (this.pathIsQualified(fileName) && fs_1.existsSync(absolute)) { | ||
this.addFile({ fileName: normalizedFilename, text: typescript_1.sys.readFile(absolute), isMainEntry: false }); | ||
return this.files.get(normalizedFilename).file; | ||
} | ||
return typescript_1.ScriptSnapshot.fromString(""); | ||
} | ||
@@ -209,4 +219,33 @@ /** | ||
} | ||
/** | ||
* Returns true if the given path is qualified | ||
* @param {string} path | ||
* @returns {boolean} | ||
*/ | ||
pathIsQualified(path) { | ||
return this.parseExternalModules ? true : !path.includes(TypescriptLanguageServiceHost.EXTERNAL_MODULES_PATH); | ||
} | ||
/** | ||
* Normalizes the given file name | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
normalizeFilename(fileName) { | ||
return path_1.isAbsolute(fileName) ? helpers_1.ensureRelative(this.appRoot, fileName) : fileName; | ||
} | ||
/** | ||
* Ensure that the given file name is in fact absolute | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
makeAbsolute(fileName) { | ||
return path_1.isAbsolute(fileName) ? fileName : path_1.join(this.appRoot, fileName); | ||
} | ||
} | ||
/** | ||
* The part of a path that matches external modules | ||
* @type {string} | ||
*/ | ||
TypescriptLanguageServiceHost.EXTERNAL_MODULES_PATH = "node_modules/"; | ||
exports.TypescriptLanguageServiceHost = TypescriptLanguageServiceHost; | ||
//# sourceMappingURL=typescript-language-service-host.js.map |
@@ -7,2 +7,3 @@ export interface ITypescriptPluginOptions { | ||
exclude: string | string[]; | ||
parseExternalModules: boolean; | ||
} |
@@ -7,2 +7,2 @@ import { Plugin } from "rollup"; | ||
*/ | ||
export default function typescriptRollupPlugin({root, tsconfig, noEmit, include, exclude}?: Partial<ITypescriptPluginOptions>): Plugin; | ||
export default function typescriptRollupPlugin({root, tsconfig, noEmit, include, exclude, parseExternalModules}?: Partial<ITypescriptPluginOptions>): Plugin; |
@@ -16,3 +16,3 @@ // tslint:disable:no-any | ||
*/ | ||
export default function typescriptRollupPlugin({ root = process.cwd(), tsconfig = "tsconfig.json", noEmit = false, include = [], exclude = [] } = {}) { | ||
export default function typescriptRollupPlugin({ root = process.cwd(), tsconfig = "tsconfig.json", noEmit = false, include = [], exclude = [], parseExternalModules = false } = {}) { | ||
/** | ||
@@ -122,3 +122,3 @@ * The CompilerOptions to use with Typescript for individual files | ||
if (languageServiceHost == null) { | ||
languageServiceHost = new TypescriptLanguageServiceHost(root, typescriptOptions); | ||
languageServiceHost = new TypescriptLanguageServiceHost(root, parseExternalModules, typescriptOptions); | ||
formatHost = new FormatHost(languageServiceHost, root); | ||
@@ -125,0 +125,0 @@ } |
@@ -0,4 +1,4 @@ | ||
import { CompilerOptions, Diagnostic, IScriptSnapshot, LanguageService, ParsedCommandLine } from "typescript"; | ||
import { ITypescriptLanguageServiceEmitResult } from "./i-typescript-language-service-emit-result"; | ||
import { ITypescriptLanguageServiceFileBase } from "./i-typescript-language-service-file"; | ||
import { LanguageService, ParsedCommandLine, CompilerOptions, IScriptSnapshot, Diagnostic } from "typescript"; | ||
import { ITypescriptLanguageServiceHost } from "./i-typescript-language-service-host"; | ||
@@ -10,4 +10,10 @@ /** | ||
private readonly appRoot; | ||
private readonly parseExternalModules; | ||
private typescriptOptions; | ||
/** | ||
* The part of a path that matches external modules | ||
* @type {string} | ||
*/ | ||
private static readonly EXTERNAL_MODULES_PATH; | ||
/** | ||
* The LanguageService host to use. Will be equal to this instance | ||
@@ -22,3 +28,3 @@ * @type {LanguageService} | ||
private readonly files; | ||
constructor(appRoot: string, typescriptOptions: ParsedCommandLine); | ||
constructor(appRoot: string, parseExternalModules: boolean, typescriptOptions: ParsedCommandLine); | ||
/** | ||
@@ -61,8 +67,2 @@ * Gets the CompilerOptions | ||
/** | ||
* Gets the Script text for the given file name | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
getScriptText(fileName: string): string; | ||
/** | ||
* Gets a Script Snapshot for the given file name | ||
@@ -72,3 +72,3 @@ * @param {string} fileName | ||
*/ | ||
getScriptSnapshot(fileName: string): IScriptSnapshot; | ||
getScriptSnapshot(fileName: string): IScriptSnapshot | undefined; | ||
/** | ||
@@ -145,2 +145,20 @@ * Gets the text of all files | ||
emit(fileName: string, onlyDeclarations?: boolean): ITypescriptLanguageServiceEmitResult[]; | ||
/** | ||
* Returns true if the given path is qualified | ||
* @param {string} path | ||
* @returns {boolean} | ||
*/ | ||
private pathIsQualified(path); | ||
/** | ||
* Normalizes the given file name | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
private normalizeFilename(fileName); | ||
/** | ||
* Ensure that the given file name is in fact absolute | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
private makeAbsolute(fileName); | ||
} |
@@ -0,5 +1,7 @@ | ||
import { existsSync } from "fs"; | ||
import { isAbsolute, join } from "path"; | ||
import { createDocumentRegistry, createLanguageService, createProgram, getDefaultLibFilePath, getPreEmitDiagnostics, ScriptSnapshot, sys } from "typescript"; | ||
import { DECLARATION_EXTENSION, SOURCE_MAP_EXTENSION } from "./constants"; | ||
import { ensureRelative } from "./helpers"; | ||
import { TypescriptLanguageServiceEmitResultKind } from "./i-typescript-language-service-emit-result"; | ||
import { createLanguageService, createDocumentRegistry, ScriptSnapshot, sys, getDefaultLibFilePath, createProgram, getPreEmitDiagnostics } from "typescript"; | ||
import { DECLARATION_EXTENSION, SOURCE_MAP_EXTENSION } from "./constants"; | ||
/** | ||
@@ -9,4 +11,5 @@ * A LanguageServiceHost for Typescript | ||
export class TypescriptLanguageServiceHost { | ||
constructor(appRoot, typescriptOptions) { | ||
constructor(appRoot, parseExternalModules, typescriptOptions) { | ||
this.appRoot = appRoot; | ||
this.parseExternalModules = parseExternalModules; | ||
this.typescriptOptions = typescriptOptions; | ||
@@ -54,5 +57,11 @@ /** | ||
addFile(file) { | ||
const existing = this.files.get(file.fileName); | ||
const version = existing != null ? `${parseInt(existing.version) + 1}` : "1"; | ||
this.files.set(file.fileName, Object.assign({}, file, { file: ScriptSnapshot.fromString(file.text), version })); | ||
const normalizedFilename = this.normalizeFilename(file.fileName); | ||
const existing = this.files.get(normalizedFilename); | ||
this.files.set(normalizedFilename, { | ||
fileName: normalizedFilename, | ||
text: file.text, | ||
isMainEntry: file.isMainEntry, | ||
file: ScriptSnapshot.fromString(file.text), | ||
version: existing != null ? `${parseInt(existing.version) + 1}` : "1" | ||
}); | ||
} | ||
@@ -64,3 +73,4 @@ /** | ||
removeFile(fileName) { | ||
this.files.delete(fileName); | ||
const normalizedFilename = this.normalizeFilename(fileName); | ||
this.files.delete(normalizedFilename); | ||
} | ||
@@ -84,11 +94,2 @@ /** | ||
/** | ||
* Gets the Script text for the given file name | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
getScriptText(fileName) { | ||
const file = this.files.get(fileName); | ||
return file == null ? "" : file.text; | ||
} | ||
/** | ||
* Gets a Script Snapshot for the given file name | ||
@@ -99,3 +100,12 @@ * @param {string} fileName | ||
getScriptSnapshot(fileName) { | ||
return ScriptSnapshot.fromString(this.getScriptText(fileName)); | ||
const normalizedFilename = this.normalizeFilename(fileName); | ||
const absolute = this.makeAbsolute(normalizedFilename); | ||
if (this.files.has(normalizedFilename)) { | ||
return this.files.get(normalizedFilename).file; | ||
} | ||
if (this.pathIsQualified(fileName) && existsSync(absolute)) { | ||
this.addFile({ fileName: normalizedFilename, text: sys.readFile(absolute), isMainEntry: false }); | ||
return this.files.get(normalizedFilename).file; | ||
} | ||
return ScriptSnapshot.fromString(""); | ||
} | ||
@@ -207,3 +217,32 @@ /** | ||
} | ||
/** | ||
* Returns true if the given path is qualified | ||
* @param {string} path | ||
* @returns {boolean} | ||
*/ | ||
pathIsQualified(path) { | ||
return this.parseExternalModules ? true : !path.includes(TypescriptLanguageServiceHost.EXTERNAL_MODULES_PATH); | ||
} | ||
/** | ||
* Normalizes the given file name | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
normalizeFilename(fileName) { | ||
return isAbsolute(fileName) ? ensureRelative(this.appRoot, fileName) : fileName; | ||
} | ||
/** | ||
* Ensure that the given file name is in fact absolute | ||
* @param {string} fileName | ||
* @returns {string} | ||
*/ | ||
makeAbsolute(fileName) { | ||
return isAbsolute(fileName) ? fileName : join(this.appRoot, fileName); | ||
} | ||
} | ||
/** | ||
* The part of a path that matches external modules | ||
* @type {string} | ||
*/ | ||
TypescriptLanguageServiceHost.EXTERNAL_MODULES_PATH = "node_modules/"; | ||
//# sourceMappingURL=typescript-language-service-host.js.map |
{ | ||
"name": "@wessberg/rollup-plugin-ts", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "A Rollup plugin for Typescript", | ||
@@ -41,9 +41,9 @@ "scripts": { | ||
"@wessberg/ts-config": "^0.0.26", | ||
"conventional-changelog-cli": "^1.3.17", | ||
"conventional-changelog-cli": "^1.3.21", | ||
"husky": "latest", | ||
"tslint": "^5.9.1", | ||
"typescript": "^2.7.2" | ||
"typescript": "^2.8.1" | ||
}, | ||
"dependencies": { | ||
"@types/node": "^9.6.1", | ||
"@types/node": "^9.6.2", | ||
"chalk": "^2.3.2", | ||
@@ -50,0 +50,0 @@ "rollup": "^0.57.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111637
1857
2
Updated@types/node@^9.6.2