Skip to content

Commit

Permalink
feat(eyeglass): New option to disable strict dependency checks for im…
Browse files Browse the repository at this point in the history
…ports.
  • Loading branch information
chriseppstein committed Apr 2, 2019
1 parent 70e0d72 commit 5919fce
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
36 changes: 23 additions & 13 deletions packages/eyeglass/src/modules/EyeglassModules.ts
Expand Up @@ -188,14 +188,13 @@ export default class EyeglassModules {
access(name: string, origin: string): EyeglassModule | null {
let mod = this.find(name);

// if we have a module, ensure that we can access it from the origin
if (mod && !this.canAccessModule(name, origin)) {
// if the module exists and we can access the module from the origin
if (mod && this.canAccessModule(name, origin)) {
return mod;
} else {
// if not, return null
return null;
}

// otherwise, return the module reference
return mod!;
}

/**
Expand Down Expand Up @@ -561,14 +560,25 @@ export default class EyeglassModules {
}
});

/* istanbul ignore next - don't test debug */
debug.importer(
"%s can%s be imported from %s",
name,
(canAccess ? "" : "not"),
origin
);
return canAccess;
// If strict dependency checks are disabled, just return the true.
if (!canAccess && this.config.eyeglass.disableStrictDependencyCheck) {
debug.warning(
"Overriding strict dependency check for %s from %s",
name,
origin
);
return true;
} else {
/* istanbul ignore next - don't test debug */
debug.importer(
"%s can%s be imported from %s",
name,
(canAccess ? "" : "not"),
origin
);
return canAccess;
}

});
};

Expand Down
15 changes: 15 additions & 0 deletions packages/eyeglass/src/util/Options.ts
Expand Up @@ -126,6 +126,21 @@ export interface EyeglassSpecificOptions<ExtraSandboxTypes = true | string> {
* more than once with incompatible semantic versions.
*/
strictModuleVersions?: boolean | "warn";
/**
* Default to false.
*
* Whether to disable the strict dependency check that ensures
* that Sass files in an eyeglass eyeglass module can only import sass files
* from the eyeglass modules that it depends on directly.
*
* When true, a Sass file will be able to import from any eyeglass
* module that is found in the module tree.
*
* This is not recommended, but may be necessary when working with manually
* declared modules which currently lack a well-defined mechanism for
* declaring dependencies on other manual modules.
*/
disableStrictDependencyCheck?: boolean;
/**
* When strictModuleVersions checking is enabled,
* this asserts that the modules installed are compatible with the
Expand Down
1 change: 1 addition & 0 deletions packages/eyeglass/src/util/debug.ts
Expand Up @@ -2,5 +2,6 @@ import * as debug from "debug";

export const importer = debug("eyeglass:importer");
export const modules = debug("eyeglass:modules");
export const warning = debug("eyeglass:warning");
export const functions = debug("eyeglass:functions");
export const assets = debug("eyeglass:assets");
13 changes: 13 additions & 0 deletions packages/eyeglass/test/test_imports.js
Expand Up @@ -206,6 +206,19 @@ describe("eyeglass importer", function () {
testutils.assertCompiles(options, expected, done);
});

it("lets you import transitive sass files when strict module checks are disabled", function (done) {
var options = {
file: "wubwubwub.scss",
data: '@import "transitive_module";',
eyeglass: {
disableStrictDependencyCheck: true,
root: testutils.fixtureDirectory("basic_modules")
}
};
var expected = ".transitive_module {\n hello: world; }\n";
testutils.assertCompiles(options, expected, done);
});

it("does not let you import transitive sass files", function (done) {
testutils.assertStderr(function(checkStderr) {
var options = {
Expand Down

0 comments on commit 5919fce

Please sign in to comment.