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: update type declarations, allow context to be undefined #16

Open
wants to merge 2 commits into
base: master
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 src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function postcss(opts: d.PluginOptions = {}): d.Plugin {
return null;
}

if (!context || !util.usePlugin(fileName)) {
if (!util.usePlugin(fileName)) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export function getRenderOptions(opts: d.PluginOptions, sourceText: string, cont

const injectGlobalPaths = Array.isArray(opts.injectGlobalPaths) ? opts.injectGlobalPaths.slice() : [];

if (injectGlobalPaths.length > 0) {
if (context && injectGlobalPaths.length > 0) {
// automatically inject each of these paths into the source text
const injectText = injectGlobalPaths.map(injectGlobalPath => {
if (!path.isAbsolute(injectGlobalPath)) {
if (!path.isAbsolute(injectGlobalPath) && context.config.rootDir) {
// convert any relative paths to absolute paths relative to the project root
injectGlobalPath = path.join(context.config.rootDir, injectGlobalPath);
}
Expand Down
10 changes: 10 additions & 0 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ describe('getRenderOptions', () => {
expect(output.plugins).toHaveLength(0);
});

it('should not break with undefined context', () => {
const input: d.PluginOptions = {
injectGlobalPaths: ['./my/global/variables.pcss']
};

expect(() => {
const output = util.getRenderOptions(input, undefined, undefined);
}).not.toThrow();
});

});


Expand Down