-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Excluding default
from conditions
#30
Comments
A proposal with Type: When truthy, the resolve.exports(pkg, '.', { noDefault: true });
//=> Conditions: ["import", "node"]
resolve.exports(pkg, '.', {
noDefault: true,
unsafe: true,
conditions: ['types'],
});
//=> Conditions: ["types"] export function conditions(options: t.Options): Set<t.Condition> {
let out = new Set(options.conditions || []);
options.noDefault || out.add('default');
options.unsafe || out.add(options.require ? 'require' : 'import');
options.unsafe || out.add(options.browser ? 'browser' : 'node');
return out;
} An other proposal with Type: When truthy, the resolve.exports(pkg, '.', { types: true });
//=> Conditions: ["types"]
resolve.exports(pkg, '.', {
types: true,
conditions: ['typings'],
});
//=> Conditions: ["types", "typings"] export function conditions(options: t.Options): Set<t.Condition> {
let out = new Set(options.conditions || []);
if (options.unsafe) {
out.add('default');
} else if (options.types) {
out.add('types');
} else {
out.add('default');
out.add(options.require ? 'require' : 'import');
out.add(options.browser ? 'browser' : 'node');
}
return out;
} |
The first option sounds the most reusable (in case there were any other use cases for dropping |
Why not simply an array of the conditions you want to check? Then it's not specific to "default", or to types. |
That's what |
ahhhh, gotcha. then yeah i'd go with |
that'd work for me too, though I do see an argument for having |
A third proposal with negative conditions: If you want to undo one of default conditions, you can use the resolve.exports(pkg, '.');
//=> Conditions: ["default", "import", "node"]
resolve.exports(pkg, '.', { conditions: ['!import'] });
//=> Conditions: ["default", "node"]
resolve.exports(pkg, '.', { conditions: ['!node', 'deno'] });
//=> Conditions: ["default", "import", "deno"]
resolve.exports(pkg, '.', { conditions: ['!default', '!import', '!node', 'types'] });
//=> Conditions: ["types"]
resolve.exports(pkg, '.', { conditions: ['!import', 'require'] }); // Same as { require: true }.
//=> Conditions: ["default", "require", "node"]
resolve.exports(pkg, '.', { conditions: ['!node', 'browser'] }); // Same as { browser: true }.
//=> Conditions: ["default", "import", "browser"]
resolve.exports(pkg, '.', { conditions: ['!import', '!node'] }); // Same as { unsafe: true }.
//=> Conditions: ["default"] export function conditions(options: t.Options): Set<t.Condition> {
let out = new Set(['default']);
options.unsafe || out.add(options.require ? 'require' : 'import');
options.unsafe || out.add(options.browser ? 'browser' : 'node');
for (const condition of options.conditions || []) {
if (condition.startsWith('!')) {
out.delete(condition.slice(1));
} else {
out.add(condition);
}
}
return out;
} If you want to remove export function conditions(options: t.Options): Set<t.Condition> {
let out = new Set(['default', 'import', 'node']);
for (const condition of options.conditions || []) {
if (condition.startsWith('!')) {
out.delete(condition.slice(1));
} else {
out.add(condition);
}
}
return out;
} |
I'm fine myself with the latter approach added to #31 . If that's ok, can it be reviewed? |
Hi,
Great to find such a library, thank you.
I was wondering whether you might add an option such as
noDefault
to remove checking fordefault
inexports
.https://github.com/lukeed/resolve.exports/blob/master/src/utils.ts#L16
I'm only interested in
types
ortypings
.Thanks!
The text was updated successfully, but these errors were encountered: