mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
- tslib imports
This commit is contained in:
parent
3573518406
commit
cb3a4df7c5
28
dist/rollup-plugin-typescript2.cjs.js
vendored
28
dist/rollup-plugin-typescript2.cjs.js
vendored
@ -19,6 +19,14 @@ const __assign = Object.assign || function (target) {
|
||||
};
|
||||
|
||||
var _ = require("lodash");
|
||||
function getDefaultOptions() {
|
||||
return {
|
||||
noEmitHelpers: true,
|
||||
module: ts.ModuleKind.ES2015,
|
||||
sourceMap: true,
|
||||
importHelpers: true,
|
||||
};
|
||||
}
|
||||
// Gratefully lifted from 'look-up', due to problems using it directly:
|
||||
// https://github.com/jonschlinkert/look-up/blob/master/index.js
|
||||
// MIT Licenced
|
||||
@ -38,11 +46,22 @@ function findFile(cwd, filename) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// The injected id for helpers.
|
||||
var TSLIB = "tslib";
|
||||
var tslibSource;
|
||||
try {
|
||||
var tslibPath = require.resolve("tslib/" + require("tslib/package.json")["module"]);
|
||||
tslibSource = fs.readFileSync(tslibPath, "utf8");
|
||||
}
|
||||
catch (e) {
|
||||
console.warn("Error loading `tslib` helper library.");
|
||||
throw e;
|
||||
}
|
||||
function parseTsConfig() {
|
||||
var fileName = findFile(process.cwd(), "tsconfig.json");
|
||||
var text = ts.sys.readFile(fileName);
|
||||
var result = ts.parseConfigFileTextToJson(fileName, text);
|
||||
var configParseResult = ts.parseJsonConfigFileContent(result.config, ts.sys, path.dirname(fileName), undefined, fileName);
|
||||
var configParseResult = ts.parseJsonConfigFileContent(result.config, ts.sys, path.dirname(fileName), getDefaultOptions(), fileName);
|
||||
return configParseResult;
|
||||
}
|
||||
function printDiagnostics(context, diagnostics) {
|
||||
@ -80,6 +99,8 @@ function typescript(options) {
|
||||
var services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry());
|
||||
return {
|
||||
resolveId: function (importee, importer) {
|
||||
if (importee === TSLIB)
|
||||
return "\0" + TSLIB;
|
||||
if (!importer)
|
||||
return null;
|
||||
importer = importer.split("\\").join("/");
|
||||
@ -92,9 +113,8 @@ function typescript(options) {
|
||||
return null;
|
||||
},
|
||||
load: function (id) {
|
||||
if (!filter(id))
|
||||
return null;
|
||||
return ""; // avoiding double loading
|
||||
if (id === "\0" + TSLIB)
|
||||
return tslibSource;
|
||||
},
|
||||
transform: function (_code, id) {
|
||||
if (!filter(id))
|
||||
|
||||
30
dist/rollup-plugin-typescript2.es.js
vendored
30
dist/rollup-plugin-typescript2.es.js
vendored
@ -2,7 +2,7 @@
|
||||
import { ModuleKind, ScriptSnapshot, createDocumentRegistry, createLanguageService, flattenDiagnosticMessageText, getDefaultLibFilePath, nodeModuleNameResolver, parseConfigFileTextToJson, parseJsonConfigFileContent, sys } from 'typescript';
|
||||
import * as ts from 'typescript';
|
||||
import { createFilter } from 'rollup-pluginutils';
|
||||
import { existsSync } from 'fs';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import * as fs from 'fs';
|
||||
import { dirname, sep } from 'path';
|
||||
import * as path from 'path';
|
||||
@ -20,6 +20,14 @@ const __assign = Object.assign || function (target) {
|
||||
};
|
||||
|
||||
var _ = require("lodash");
|
||||
function getDefaultOptions() {
|
||||
return {
|
||||
noEmitHelpers: true,
|
||||
module: ModuleKind.ES2015,
|
||||
sourceMap: true,
|
||||
importHelpers: true,
|
||||
};
|
||||
}
|
||||
// Gratefully lifted from 'look-up', due to problems using it directly:
|
||||
// https://github.com/jonschlinkert/look-up/blob/master/index.js
|
||||
// MIT Licenced
|
||||
@ -39,11 +47,22 @@ function findFile(cwd, filename) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// The injected id for helpers.
|
||||
var TSLIB = "tslib";
|
||||
var tslibSource;
|
||||
try {
|
||||
var tslibPath = require.resolve("tslib/" + require("tslib/package.json")["module"]);
|
||||
tslibSource = readFileSync(tslibPath, "utf8");
|
||||
}
|
||||
catch (e) {
|
||||
console.warn("Error loading `tslib` helper library.");
|
||||
throw e;
|
||||
}
|
||||
function parseTsConfig() {
|
||||
var fileName = findFile(process.cwd(), "tsconfig.json");
|
||||
var text = sys.readFile(fileName);
|
||||
var result = parseConfigFileTextToJson(fileName, text);
|
||||
var configParseResult = parseJsonConfigFileContent(result.config, sys, dirname(fileName), undefined, fileName);
|
||||
var configParseResult = parseJsonConfigFileContent(result.config, sys, dirname(fileName), getDefaultOptions(), fileName);
|
||||
return configParseResult;
|
||||
}
|
||||
function printDiagnostics(context, diagnostics) {
|
||||
@ -81,6 +100,8 @@ function typescript(options) {
|
||||
var services = createLanguageService(servicesHost, createDocumentRegistry());
|
||||
return {
|
||||
resolveId: function (importee, importer) {
|
||||
if (importee === TSLIB)
|
||||
return "\0" + TSLIB;
|
||||
if (!importer)
|
||||
return null;
|
||||
importer = importer.split("\\").join("/");
|
||||
@ -93,9 +114,8 @@ function typescript(options) {
|
||||
return null;
|
||||
},
|
||||
load: function (id) {
|
||||
if (!filter(id))
|
||||
return null;
|
||||
return ""; // avoiding double loading
|
||||
if (id === "\0" + TSLIB)
|
||||
return tslibSource;
|
||||
},
|
||||
transform: function (_code, id) {
|
||||
if (!filter(id))
|
||||
|
||||
35
src/index.ts
35
src/index.ts
@ -5,6 +5,16 @@ import * as path from "path";
|
||||
import { existsSync } from "fs";
|
||||
const _ = require("lodash") as lodash;
|
||||
|
||||
function getDefaultOptions()
|
||||
{
|
||||
return {
|
||||
noEmitHelpers: true,
|
||||
module: ts.ModuleKind.ES2015,
|
||||
sourceMap: true,
|
||||
importHelpers: true,
|
||||
};
|
||||
}
|
||||
|
||||
// Gratefully lifted from 'look-up', due to problems using it directly:
|
||||
// https://github.com/jonschlinkert/look-up/blob/master/index.js
|
||||
// MIT Licenced
|
||||
@ -33,12 +43,25 @@ function findFile(cwd: string, filename: string)
|
||||
return null;
|
||||
}
|
||||
|
||||
// The injected id for helpers.
|
||||
const TSLIB = "tslib";
|
||||
let tslibSource: string;
|
||||
try
|
||||
{
|
||||
const tslibPath = require.resolve("tslib/" + require("tslib/package.json")["module"]);
|
||||
tslibSource = fs.readFileSync(tslibPath, "utf8");
|
||||
} catch (e)
|
||||
{
|
||||
console.warn("Error loading `tslib` helper library.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
function parseTsConfig()
|
||||
{
|
||||
const fileName = findFile(process.cwd(), "tsconfig.json");
|
||||
const text = ts.sys.readFile(fileName);
|
||||
const result = ts.parseConfigFileTextToJson(fileName, text);
|
||||
const configParseResult = ts.parseJsonConfigFileContent(result.config, ts.sys, path.dirname(fileName), undefined, fileName);
|
||||
const configParseResult = ts.parseJsonConfigFileContent(result.config, ts.sys, path.dirname(fileName), getDefaultOptions(), fileName);
|
||||
|
||||
return configParseResult;
|
||||
}
|
||||
@ -52,7 +75,7 @@ interface Context
|
||||
warn(message: Message): void;
|
||||
error(message: Message): void;
|
||||
}
|
||||
function printDiagnostics(context: Context, diagnostics: ts.Diagnostic[])
|
||||
function printDiagnostics(context: Context, diagnostics: ts.Diagnostic[])
|
||||
{
|
||||
diagnostics.forEach((diagnostic) =>
|
||||
{
|
||||
@ -102,6 +125,9 @@ export default function typescript (options: any)
|
||||
|
||||
resolveId(importee: string, importer: string)
|
||||
{
|
||||
if (importee === TSLIB)
|
||||
return "\0" + TSLIB;
|
||||
|
||||
if (!importer)
|
||||
return null;
|
||||
|
||||
@ -122,9 +148,8 @@ export default function typescript (options: any)
|
||||
|
||||
load(id: string): any
|
||||
{
|
||||
if (!filter(id))
|
||||
return null;
|
||||
return ""; // avoiding double loading
|
||||
if (id === "\0" + TSLIB)
|
||||
return tslibSource;
|
||||
},
|
||||
|
||||
transform(this: Context, _code: string, id: string): any
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user