Skip to content

Commit 74f6761

Browse files
authored
docs/clean: formally deprecate rollupCommonJSResolveHack (ezolenko#367)
* docs/clean: formally deprecate `rollupCommonJSResolveHack` - this has had no effect since 6fb0e75, released in 0.30.0 - that changed the code to always return OS native paths via the NodeJS Path API - so setting `rollupCommonJSResolveHack` would make no difference either `true` or `false` - effectively, it's as if it's always `true` now - formally state now that this is deprecated in the docs - as well as when that occurred and what it means - also add a warning in `options` similar to the existing one for `objectHashIgnoreUnknownHack` - remove the `resolve` dependency as well - it turns out something in the devDeps still uses it, so it didn't get fully removed in the `package-lock.json` - `resolve` was never needed anyway as we could've used NodeJS's native `path.resolve` or `require.resolve` instead - `resolve` was created for `browserify` after all, where one can't use NodeJS APIs - but we run on NodeJS and can and already do use NodeJS APIs, including both `path.resolve` _and_ `require.resolve` - I actually started this commit just to remove the dep, then realized the entire code path is obsolete * fix lint error -- resolved can now be const
1 parent b0e3922 commit 74f6761

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,7 @@ See [#108](https://github.com/ezolenko/rollup-plugin-typescript2/issues/108)
156156

157157
* `rollupCommonJSResolveHack`: false
158158

159-
On windows typescript resolver favors POSIX path, while commonjs plugin (and maybe others?) uses native path as module id. This can result in `namedExports` being ignored if rollup happened to use typescript's resolution. Set to true to pass resolved module path through `resolve()` to match up with `rollup-plugin-commonjs`.
160-
161-
`rollup-plugin-commonjs` fixed this in `10.1.0`, so projects using this option who update to new version will be broken again.
162-
163-
This also works around the similar bug affecting code splitting (see [rollup/rollup#3094](https://github.com/rollup/rollup/issues/3094)).
159+
_Deprecated_. OS native paths are now _always_ used since [`0.30.0`](https://github.com/ezolenko/rollup-plugin-typescript2/releases/0.30.0) (see [#251](https://github.com/ezolenko/rollup-plugin-typescript2/pull/251)), so this no longer has any effect -- as if it is always `true`.
164160

165161
* `objectHashIgnoreUnknownHack`: false
166162

package-lock.json

+12-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@rollup/pluginutils": "^4.1.2",
3636
"find-cache-dir": "^3.3.2",
3737
"fs-extra": "^10.0.0",
38-
"resolve": "^1.20.0",
3938
"tslib": "^2.4.0"
4039
},
4140
"peerDependencies": {

src/index.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { relative, dirname, normalize as pathNormalize, resolve as pathResolve } from "path";
1+
import { relative, dirname, normalize as pathNormalize, resolve } from "path";
22
import * as tsTypes from "typescript";
33
import { PluginImpl, PluginContext, InputOptions, OutputOptions, TransformResult, SourceMap, Plugin } from "rollup";
44
import { normalizePath as normalize } from "@rollup/pluginutils";
55
import * as _ from "lodash";
66
import { blue, red, yellow, green } from "colors/safe";
7-
import * as resolve from "resolve";
87
import findCacheDir from "find-cache-dir";
98

109
import { RollupContext } from "./rollupcontext";
@@ -115,6 +114,9 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
115114
if (pluginOptions.objectHashIgnoreUnknownHack)
116115
context.warn(() => `${yellow("You are using 'objectHashIgnoreUnknownHack' option")}. If you enabled it because of async functions, try disabling it now.`);
117116

117+
if (pluginOptions.rollupCommonJSResolveHack)
118+
context.warn(() => `${yellow("You are using 'rollupCommonJSResolveHack' option")}. This is no longer needed, try disabling it now.`);
119+
118120
if (watchMode)
119121
context.info(`running in watch mode`);
120122
}
@@ -155,7 +157,7 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
155157

156158
// TODO: use module resolution cache
157159
const result = tsModule.nodeModuleNameResolver(importee, importer, parsedConfig.options, tsModule.sys);
158-
let resolved = result.resolvedModule?.resolvedFileName;
160+
const resolved = result.resolvedModule?.resolvedFileName;
159161

160162
if (!resolved)
161163
return;
@@ -166,9 +168,6 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
166168
if (resolved.endsWith(".d.ts"))
167169
return;
168170

169-
if (pluginOptions.rollupCommonJSResolveHack)
170-
resolved = resolve.sync(resolved);
171-
172171
context.debug(() => `${blue("resolving")} '${importee}' imported by '${importer}'`);
173172
context.debug(() => ` to '${resolved}'`);
174173

@@ -332,7 +331,7 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
332331
// invert back to absolute, then make relative to declarationDir
333332
parsedText.sources = parsedText.sources.map(source =>
334333
{
335-
const absolutePath = pathResolve(cachePlaceholder, source);
334+
const absolutePath = resolve(cachePlaceholder, source);
336335
return normalize(relative(declarationDir, absolutePath));
337336
});
338337
entryText = JSON.stringify(parsedText);

0 commit comments

Comments
 (0)