Skip to content

Commit

Permalink
add missing path normalization when calling classifyModule
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Jun 14, 2021
1 parent 7bd2076 commit dcbd916
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dist-raw/node-cjs-loader-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const path = require('path');
const packageJsonReader = require('./node-package-json-reader');
const {JSONParse} = require('./node-primordials');
const {normalizeSlashes} = require('../dist/util');

module.exports.assertScriptCanLoadAsCJSImpl = assertScriptCanLoadAsCJSImpl;

Expand All @@ -19,7 +20,7 @@ function assertScriptCanLoadAsCJSImpl(service, module, filename) {
const pkg = readPackageScope(filename);

// ts-node modification: allow our configuration to override
const tsNodeClassification = service.moduleTypeClassifier.classifyModule(filename);
const tsNodeClassification = service.moduleTypeClassifier.classifyModule(normalizeSlashes(filename));
if(tsNodeClassification.moduleType === 'cjs') return;

// Function require shouldn't be used in ES modules.
Expand Down
5 changes: 3 additions & 2 deletions src/module-type-classifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export type ModuleTypeClassifier = ReturnType<
>;
/**
* @internal
* May receive non-normalized basePath and patterns and will normalize them
* May receive non-normalized options -- basePath and patterns -- and will normalize them
* internally.
* However, calls to `classifyModule` must pass pre-normalized paths!
*/
export function createModuleTypeClassifier(
options: ModuleTypeClassifierOptions
Expand Down Expand Up @@ -52,7 +53,7 @@ export function createModuleTypeClassifier(
};
const auto = classifications.package;

// TODO path must be normalized.
// Passed path must be normalized!
function classifyModuleNonCached(path: string): ModuleTypeClassification {
const matched = matchPatterns(patternTypePairs, (_) => _.pattern, path);
if (matched) return classifications[matched.type];
Expand Down

0 comments on commit dcbd916

Please sign in to comment.