Skip to content

Commit 84d5419

Browse files
committed
fix(core): Remove stray console.log. Add debug logs.
1 parent fc508eb commit 84d5419

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/@css-blocks/core/src/importing/NodeJsImporter.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ObjectDictionary } from "@opticss/util";
22

3+
import * as debugGenerator from "debug";
34
import { existsSync, readFile, readFileSync } from "fs-extra";
45
import * as path from "path";
56

@@ -8,6 +9,8 @@ import { ResolvedConfiguration } from "../configuration";
89

910
import { FileIdentifier, ImportedFile, Importer } from "./Importer";
1011

12+
const debug = debugGenerator("css-blocks:importer");
13+
1114
const DEFAULT_MAIN = "blocks/index.block.css";
1215

1316
/**
@@ -48,27 +51,33 @@ export class NodeJsImporter implements Importer {
4851
let fromDir = from ? path.dirname(from) : config.rootDir;
4952
let resolvedPath = path.resolve(fromDir, importPath);
5053
if (existsSync(resolvedPath)) { return resolvedPath; }
54+
debug(`No relative or absolute Block file discovered for ${importPath}.`);
5155

5256
// If not a real file, attempt to resolve to an aliased path instead.
5357
let alias = this.aliases.find(a => importPath.startsWith(a.alias + path.sep));
5458
if (alias) {
5559
return path.resolve(alias.path, importPath.substring(alias.alias.length + 1));
5660
}
61+
debug(`No file path alias discovered for ${importPath}.`);
5762

5863
// If no alias found, test for a node_module resolution as a file path.
5964
try {
6065
return require.resolve(importPath, { paths: [config.rootDir] });
61-
} catch (err) {}
66+
} catch (err) {
67+
debug(`Could not resolve ${importPath} as a file. Resolution failed with ${err.message}.`);
68+
}
6269

63-
// If no alias found, test for a node_module resolution as a package name.
70+
// If no file found, test for a node_module resolution as a package name.
6471
try {
6572
const pjsonPath = require.resolve(path.join(importPath, "package.json"), { paths: [config.rootDir] });
6673
const pjson = JSON.parse(readFileSync(pjsonPath, "utf-8"));
6774
const main: string | undefined = pjson["css-blocks"] && pjson["css-blocks"].main;
6875
return path.resolve(pjsonPath, "..", main || DEFAULT_MAIN);
69-
} catch (err) { console.log(err); }
76+
} catch (err) {
77+
debug(`Could not resolve ${importPath} as a module. Resolution failed with ${err.message}.`);
78+
}
7079

71-
// If no backup alias or node_module fount, return the previously calculated
80+
// If no backup alias or node_module found, return the previously calculated
7281
// absolute path where we expect it should be.
7382
return resolvedPath;
7483
}

0 commit comments

Comments
 (0)