Skip to content

Commit ad13f8e

Browse files
author
Martynas Žilinskas
authored
Using projectDirectory instead of rootDir. (#83)
1 parent 9f111cb commit ad13f8e

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/cli/main.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ function bundleResultForEach(bundleResult: BundleResult, cb: (bundleResult: Bund
3434
}
3535
}
3636

37-
async function build(project: string, config: BundlerOptions): Promise<{ bundleResult: BundleResult; fileRegistry: FileRegistry }> {
37+
async function build(
38+
project: string | undefined,
39+
config: BundlerOptions
40+
): Promise<{ bundleResult: BundleResult; fileRegistry: FileRegistry }> {
3841
if (config.entryFile == null) {
3942
throw new EntryFileNotDefinedError();
4043
}
@@ -44,16 +47,16 @@ async function build(project: string, config: BundlerOptions): Promise<{ bundleR
4447
}
4548

4649
const fileRegistry: FileRegistry = {};
47-
const bundler = new Bundler(fileRegistry, config.rootDir);
50+
const bundler = new Bundler(fileRegistry, project);
4851
const bundleResult = await bundler.bundle(config.entryFile, config.dedupeGlobs, config.includePaths, config.ignoreImports);
4952

5053
if (!bundleResult.found) {
5154
throw new EntryFileNotFoundError(bundleResult.filePath);
5255
}
5356

5457
bundleResultForEach(bundleResult, result => {
55-
if (!result.found && result.tilde && config.rootDir == null) {
56-
Log.warn("Found tilde import, but rootDir was not specified.");
58+
if (!result.found && result.tilde && project == null) {
59+
Log.warn(`Found tilde import, but "project" was not specified.`);
5760
throw new ImportFileNotFoundError(result.filePath);
5861
}
5962
});
@@ -118,10 +121,6 @@ async function main(argv: string[]): Promise<void> {
118121
const configLocationDir = path.dirname(configLocation);
119122
projectLocation = path.resolve(configLocationDir, config.project ?? "./");
120123
}
121-
if (projectLocation == null) {
122-
Log.error(`Could not resolve "project" directory.`);
123-
process.exit(1);
124-
}
125124

126125
let resolvedLogLevel: LogLevelDesc | undefined;
127126
if (config.logLevel != null) {
@@ -137,13 +136,15 @@ async function main(argv: string[]): Promise<void> {
137136
const onFileChange = debounce(async () => {
138137
Log.info("File changes detected.");
139138

140-
// This is already checked as fail fast.
141-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
142-
await build(projectLocation!, config);
139+
await build(projectLocation, config);
143140
Log.info("Waiting for changes...");
144141
});
145142

146-
const watchFolder = config.rootDir != null ? config.rootDir : projectLocation;
143+
if (config.rootDir) {
144+
Log.warn("rootDir property is missing, using cwd.");
145+
}
146+
147+
const watchFolder = config.rootDir ?? process.cwd();
147148

148149
Log.info("Waiting for changes...");
149150
chokidar.watch(watchFolder).on("change", onFileChange);

src/cli/utils/scss.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ function sassImporter(projectPath: string): nodeSass.Importer {
1515
};
1616
}
1717

18-
export async function renderScss(projectPath: string, includePaths: string[] | undefined, content: string): Promise<{}> {
18+
export async function renderScss(projectPath: string | undefined, includePaths: string[] | undefined, content: string): Promise<{}> {
1919
return new Promise((resolve, reject) => {
2020
nodeSass.render(
2121
{
2222
data: content,
23-
importer: sassImporter(projectPath),
23+
importer: projectPath != null ? sassImporter(projectPath) : undefined,
2424
includePaths: includePaths
2525
},
2626
(error, result) => {

0 commit comments

Comments
 (0)