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

test: dogfood rpt2 as configPlugin w/ rollup.config.ts #460

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -241,7 +241,7 @@ Otherwise the plugin should work in watch mode. Make sure to run a normal build

* TypeScript `2.4+`
* Rollup `1.26.3+`
* Node `6.4.0+` (basic ES6 support)
* Node `12.2.0+` (to [support `createRequire`](https://nodejs.org/api/module.html#modulecreaterequirefilename))

### Reporting bugs and Contributing

Expand Down
145 changes: 69 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions package.json
Expand Up @@ -22,15 +22,19 @@
"homepage": "https://github.com/ezolenko/rollup-plugin-typescript2",
"author": "@ezolenko",
"scripts": {
"prebuild": "rimraf dist/*",
"build": "rimraf dist/* && rollup -c",
"watch": "rollup -c rollup.config.self.js -w ",
"build-self": "rimraf dist/* && rollup -c rollup.config.self.js",
"prebuild": "rimraf dist/* build-self/*.ts build-self/*.*js",
"build": "rollup -c rollup.config.ts --configPlugin typescript2=\"{ tsconfigOverride: { compilerOptions: { resolveJsonModule: true } } }\"",
"_build-self": "rollup -c rollup.config.self.ts --configPlugin ./build-self/index.mjs=\"{ tsconfigOverride: { compilerOptions: { resolveJsonModule: true } } }\"",
"build-self": "rimraf dist/* && npm run _build-self",
"watch": "npm run _build-self -- -w ",
"lint": "tslint -c ./tslint.json src/*.ts __tests__/*.ts ./*.js",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
},
"engines": {
"node": ">=12.2.0"
},
"dependencies": {
"@rollup/pluginutils": "^4.1.2",
"find-cache-dir": "^3.3.2",
Expand All @@ -46,12 +50,13 @@
"@jest/globals": "^28.0.3",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-node-resolve": "13.2.1",
"@rollup/plugin-replace": "^5.0.0",
"@types/find-cache-dir": "^2.0.0",
"@types/fs-extra": "8.0.1",
"@types/graphlib": "2.1.7",
"@types/jest": "^27.5.0",
"@types/lodash": "4.14.161",
"@types/node": "8.0.47",
"@types/node": "^20.4.2",
"@types/object-hash": "1.3.3",
"@types/semver": "7.3.12",
"colors": "1.4.0",
Expand All @@ -61,7 +66,6 @@
"object-hash": "3.0.0",
"rimraf": "3.0.2",
"rollup": "^2.70.2",
"rollup-plugin-re": "1.0.7",
"rollup-plugin-typescript2": "0.35.0",
"ts-jest": "^28.0.0",
"tslint": "6.1.3",
Expand Down
12 changes: 7 additions & 5 deletions rollup.config.base.js → rollup.config.base.ts
@@ -1,8 +1,8 @@
import replace from "@rollup/plugin-replace";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import replace from "rollup-plugin-re";

const pkg = require("./package.json");
import pkg from "./package.json";

export default {
input: "src/index.ts",
Expand All @@ -26,14 +26,16 @@ export default {
plugins: [
replace
({
replaces:
preventAssignment: true, // remove default warning
delimiters: ["", ""], // replace all instances
values:
{
"$TS_VERSION_RANGE": pkg.peerDependencies.typescript,
"$ROLLUP_VERSION_RANGE": pkg.peerDependencies.rollup,
"$RPT2_VERSION": pkg.version,
},
}),
resolve({ jsnext: true, preferBuiltins: true, }),
resolve({ preferBuiltins: true, mainFields: ["module", "jsnext:main", "main"] }),
commonjs
({
include: "node_modules/**",
Expand All @@ -57,7 +59,7 @@ export default {
},
{
format: "es",
file: "build-self/" + pkg.module,
file: "build-self/index.mjs",
sourcemap: true,
banner: "/* eslint-disable */",
exports: "auto",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.self.js → rollup.config.self.ts
@@ -1,4 +1,4 @@
import ts from "./build-self/dist/rollup-plugin-typescript2.es";
import ts from "./build-self/index";

import config from "./rollup.config.base";

Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion src/index.ts
@@ -1,3 +1,4 @@
import { createRequire } from "module";
import { relative, dirname, normalize as pathNormalize, resolve } from "path";
import * as tsTypes from "typescript";
import { PluginImpl, InputOptions, TransformResult, SourceMap, Plugin } from "rollup";
Expand All @@ -16,7 +17,9 @@ import { convertDiagnostic, printDiagnostics } from "./diagnostics";
import { TSLIB, TSLIB_VIRTUAL, tslibSource, tslibVersion } from "./tslib";
import { createFilter } from "./get-options-overrides";

// these use globals during testing and are substituted by rollup-plugin-re during builds
const require = createRequire(import.meta.url);

// these use globals during testing and are substituted by @rollup/plugin-replace during builds
const TS_VERSION_RANGE = (global as any)?.rpt2__TS_VERSION_RANGE || "$TS_VERSION_RANGE";
const ROLLUP_VERSION_RANGE = (global as any)?.rpt2__ROLLUP_VERSION_RANGE || "$ROLLUP_VERSION_RANGE";
const RPT2_VERSION = (global as any)?.rpt2__ROLLUP_VERSION_RANGE || "$RPT2_VERSION";
Expand Down
4 changes: 3 additions & 1 deletion src/rollingcache.ts
@@ -1,9 +1,11 @@
import { existsSync, readdirSync, renameSync } from "fs";
import { emptyDirSync, ensureFileSync, readJsonSync, removeSync, writeJsonSync } from "fs-extra";
import fsExtra from "fs-extra"; // TODO: replace with fs-extra/esm once we support node16+ moduleResolution
import * as _ from "lodash";

import { ICache } from "./icache";

const { emptyDirSync, ensureFileSync, readJsonSync, removeSync, writeJsonSync } = fsExtra; // TODO: per above, replace as named exports once we support node16+ moduleResolution

/**
* Saves data in new cache folder or reads it from old one.
* Avoids perpetually growing cache and situations when things need to consider changed and then reverted data to be changed.
Expand Down
3 changes: 3 additions & 0 deletions src/tslib.ts
@@ -1,3 +1,4 @@
import { createRequire } from "module";
import { readFileSync } from "fs";

// The injected id for helpers.
Expand All @@ -6,6 +7,8 @@ export const TSLIB_VIRTUAL = "\0tslib.js";
export let tslibSource: string;
export let tslibVersion: string;

const require = createRequire(import.meta.url);

try
{
// tslint:disable-next-line:no-string-literal no-var-requires
Expand Down