Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve path of injectedGlobals relative to config file #50

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stencil/sass",
"version": "1.4.0",
"version": "2.0.0-0",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
11 changes: 7 additions & 4 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,23 @@ export function getRenderOptions(opts: d.PluginOptions, sourceText: string, file
const injectGlobalPaths = Array.isArray(opts.injectGlobalPaths) ? opts.injectGlobalPaths.slice() : [];

if (injectGlobalPaths.length > 0) {
const baseInjectPath = context.config.configPath? path.dirname(context.config.configPath) : context.config.rootDir;

// automatically inject each of these paths into the source text
const injectText = injectGlobalPaths.map((injectGlobalPath) => {
const includesNamespace = Array.isArray(injectGlobalPath);
let importPath = includesNamespace ? injectGlobalPath[0] as string : injectGlobalPath as string;

if (!path.isAbsolute(importPath)) {
// convert any relative paths to absolute paths relative to the project root
const injectedPath = path.join(baseInjectPath, importPath);

// convert any relative paths to absolute paths relative to the project root
if (context.sys && typeof context.sys.normalizePath === 'function') {
// context.sys.normalizePath added in stencil 1.11.0
importPath = context.sys.normalizePath(path.join(context.config.rootDir, importPath));
importPath = context.sys.normalizePath(injectedPath);
} else {
// TODO, eventually remove normalizePath() from @stencil/sass
importPath = normalizePath(path.join(context.config.rootDir, importPath));
importPath = normalizePath(injectedPath);
}
}

Expand Down Expand Up @@ -175,7 +178,7 @@ export function getModuleId(orgImport: string) {
}

return m;
};
}

const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
const NON_ASCII_REGEX = /[^\x00-\x80]+/;
Expand Down
3 changes: 2 additions & 1 deletion test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('getRenderOptions', () => {
const fileName = '/some/path/file-name.scss';
const context: d.PluginCtx = {
config: {
configPath: '/Users/my/app/stencil.config.ts',
rootDir: '/Users/my/app/',
srcDir: '/Users/my/app/src/',
},
Expand Down Expand Up @@ -171,4 +172,4 @@ describe('getModuleId', () => {
expect(m.filePath).toBe('');
});

});
});