-
-
Notifications
You must be signed in to change notification settings - Fork 169
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
feat(rollup.config): improve tree-shaking using preserveModules: true
#1133
feat(rollup.config): improve tree-shaking using preserveModules: true
#1133
Conversation
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
b162db6
to
aec9902
Compare
After merging this pr #1134 , you can easily check the build result |
aec9902
to
d4acfec
Compare
preserveModules: true
@samchon |
Will check this at Wednesday. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked your PR, but it still makes invalid import path.
import RandExp from '../../_external/.pnpm/randexp@0.5.3/node_modules/randexp/lib/randexp.mjs';
const ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
/* -----------------------------------------------------------
REGULAR
----------------------------------------------------------- */
const boolean = () => Math.random() < 0.5;
const integer = (min, max) => {
min ??= 0;
max ??= 100;
return Math.floor(Math.random() * (max - min + 1)) + min;
};
const bigint = (min, max) => BigInt(integer(Number(min ?? BigInt(0)), Number(max ?? BigInt(100))));
const number = (min, max) => {
min ??= 0;
max ??= 100;
return Math.random() * (max - min) + min;
};
const string = (length) => new Array(length ?? integer(5, 10))
.fill(0)
.map(() => ALPHABETS[integer(0, ALPHABETS.length - 1)])
.join("");
const array = (closure, count) => new Array(count ?? length()).fill(0).map((_e, index) => closure(index));
const pick = (array) => array[integer(0, array.length - 1)];
const length = () => integer(0, 3);
const pattern = (regex) => {
const r = new RandExp(regex);
for (let i = 0; i < 10; ++i) {
const str = r.gen();
if (regex.test(str))
return str;
}
return r.gen();
};
/* -----------------------------------------------------------
SECIAL FORMATS
----------------------------------------------------------- */
// SPECIAL CHARACTERS
const byte = () => "vt7ekz4lIoNTTS9sDQYdWKharxIFAR54+z/umIxSgUM=";
const password = () => string(integer(4, 16));
const regex = () => "/^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/";
const uuid = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
// ADDRESSES
const email = () => `${string(10)}@${string(10)}.${string(3)}`;
const hostname = () => `${string(10)}.${string(3)}`;
const idnEmail = () => email();
const idnHostname = () => hostname();
const iri = () => url();
const iriReference = () => url();
const ipv4 = () => array(() => integer(0, 255), 4).join(".");
const ipv6 = () => array(() => integer(0, 65535).toString(16), 8).join(":");
const uri = () => url();
const uriReference = () => url();
const uriTemplate = () => url();
const url = () => `https://${string(10)}.${string(3)}`;
// TIMESTAMPS
const datetime = (min, max) => new Date(number(min ?? Date.now() - 30 * DAY, max ?? Date.now() + 7 * DAY)).toISOString();
const date = (min, max) => new Date(number(min ?? 0, max ?? Date.now() * 2))
.toISOString()
.substring(0, 10);
const time = () => new Date(number(0, DAY)).toISOString().substring(11);
const duration = () => {
const period = durate([
["Y", integer(0, 100)],
["M", integer(0, 12)],
["D", integer(0, 31)],
]);
const time = durate([
["H", integer(0, 24)],
["M", integer(0, 60)],
["S", integer(0, 60)],
]);
if (period.length + time.length === 0)
return "PT0S";
return `P${period}${time.length ? "T" : ""}${time}`;
};
// POINTERS
const jsonPointer = () => `/components/schemas/${string(10)}`;
const relativeJsonPointer = () => `${integer(0, 10)}#`;
const DAY = 86400000;
const durate = (elements) => elements
.filter(([_unit, value]) => value !== 0)
.map(([unit, value]) => `${value}${unit}`)
.join("");
export { array, bigint, boolean, byte, date, datetime, duration, email, hostname, idnEmail, idnHostname, integer, ipv4, ipv6, iri, iriReference, jsonPointer, length, number, password, pattern, pick, regex, relativeJsonPointer, string, time, uri, uriReference, uriTemplate, url, uuid };
//# sourceMappingURL=RandomGenerator.mjs.map
Oh, really? I'll check it |
d4acfec
to
aeda795
Compare
I'll check after this PR solves #1142 |
The entryFileNames property in the rollup.config.js file has been modified. Now, it checks if the chunk name includes 'node_modules'. If it does, it replaces 'node_modules' with 'external' and appends '.js'. Otherwise, it returns the original name with '.js' appended.
The output directory in rollup.config.js has been changed from a variable to a relative path. This makes the configuration more readable and less prone to errors due to variable mismanagement.
The 'preserveModules' and 'preserveModulesRoot' options have been moved down in the output configuration. This change does not affect the functionality but improves the readability of the code.
The terser plugin was removed from the rollup.config.js file. This change simplifies the build process as the terser plugin was not necessary for the current project setup.
The TypeScript configuration in rollup.config.js has been updated. The module and target settings have been changed from ES2020 to ESNext. This allows the use of the latest ECMAScript features in the codebase.
aeda795
to
54779c5
Compare
commit: typia
|
@samchon I installed this and checked it on my local environment. import RandExp from '../../_external/randexp/lib/randexp.mjs'; idk why it is not working in your enviroment. |
Understood, it was not a bug in By the way, previous As far as I know, number of files does not affetct to esm tree shaking. Therefore, I am not sure if the actual bundling size is correct as the number of files increases. |
Ohhhh I got it
However, pnpm is different structure, and the path looks like this
Anyway I'll add support for pnpm |
Then no way to solve the problem in the |
@samchon Also, I investigated that this improves tree-shaking. |
95a2bff
to
dacbac7
Compare
@samchon Also, I created an experiment enviroment. Why do these differences occur? If you bundle the js files into single file, the named exports are converted into objects, so that bundlers cannnot identify those methods in the objects are from real object or named export from other files. |
679f334
to
a2590a3
Compare
The chunk name generation logic in rollup.config.js has been improved. Instead of simply replacing 'node_modules' with '_external', the new logic splits the path, replaces '/' with '_', and uses the last part of the path as the file name. This provides a more unique and descriptive chunk name. A console.table is also added to log the before and after names for easier debugging.
a2590a3
to
c0a9c0d
Compare
Great. I'll publish it to v3.5.0 at tomorrow.
Also, your github sponsorship dashboard configuration is not yet? |
Not yet Please wait |
@ryoppippi Now, I've completed May I publish v6.4 now, or do you have something more to do about the tree shake bundling? |
For now it is fine! |
It still makes invalid path in import RandExp from '../../_external/node_modules_.pnpm_randexp@0.5.3_node_modules_randexp_lib/randexp.mjs';
const ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
/* -----------------------------------------------------------
REGULAR
----------------------------------------------------------- */
const boolean = () => Math.random() < 0.5;
const integer = (min, max) => {
min ??= 0;
max ??= 100;
return Math.floor(Math.random() * (max - min + 1)) + min;
};
const bigint = (min, max) => BigInt(integer(Number(min ?? BigInt(0)), Number(max ?? BigInt(100))));
const number = (min, max) => {
min ??= 0;
max ??= 100;
return Math.random() * (max - min) + min;
};
const string = (length) => new Array(length ?? integer(5, 10))
.fill(0)
.map(() => ALPHABETS[integer(0, ALPHABETS.length - 1)])
.join("");
const array = (closure, count, unique) => {
count ??= length();
unique ??= false;
if (unique === false)
return new Array(count ?? length())
.fill(0)
.map((_e, index) => closure(index));
else {
const set = new Set();
while (set.size < count)
set.add(closure(set.size));
return Array.from(set);
}
};
const pick = (array) => array[integer(0, array.length - 1)];
const length = () => integer(0, 3);
const pattern = (regex) => {
const r = new RandExp(regex);
for (let i = 0; i < 10; ++i) {
const str = r.gen();
if (regex.test(str))
return str;
}
return r.gen();
};
/* -----------------------------------------------------------
SECIAL FORMATS
----------------------------------------------------------- */
// SPECIAL CHARACTERS
const byte = () => "vt7ekz4lIoNTTS9sDQYdWKharxIFAR54+z/umIxSgUM=";
const password = () => string(integer(4, 16));
const regex = () => "/^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/";
const uuid = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
// ADDRESSES
const email = () => `${string(10)}@${string(10)}.${string(3)}`;
const hostname = () => `${string(10)}.${string(3)}`;
const idnEmail = () => email();
const idnHostname = () => hostname();
const iri = () => url();
const iriReference = () => url();
const ipv4 = () => array(() => integer(0, 255), 4).join(".");
const ipv6 = () => array(() => integer(0, 65535).toString(16), 8).join(":");
const uri = () => url();
const uriReference = () => url();
const uriTemplate = () => url();
const url = () => `https://${string(10)}.${string(3)}`;
// TIMESTAMPS
const datetime = (min, max) => new Date(number(min ?? Date.now() - 30 * DAY, max ?? Date.now() + 7 * DAY)).toISOString();
const date = (min, max) => new Date(number(min ?? 0, max ?? Date.now() * 2))
.toISOString()
.substring(0, 10);
const time = () => new Date(number(0, DAY)).toISOString().substring(11);
const duration = () => {
const period = durate([
["Y", integer(0, 100)],
["M", integer(0, 12)],
["D", integer(0, 31)],
]);
const time = durate([
["H", integer(0, 24)],
["M", integer(0, 60)],
["S", integer(0, 60)],
]);
if (period.length + time.length === 0)
return "PT0S";
return `P${period}${time.length ? "T" : ""}${time}`;
};
// POINTERS
const jsonPointer = () => `/components/schemas/${string(10)}`;
const relativeJsonPointer = () => `${integer(0, 10)}#`;
const DAY = 86400000;
const durate = (elements) => elements
.filter(([_unit, value]) => value !== 0)
.map(([unit, value]) => `${value}${unit}`)
.join("");
export { array, bigint, boolean, byte, date, datetime, duration, email, hostname, idnEmail, idnHostname, integer, ipv4, ipv6, iri, iriReference, jsonPointer, length, number, password, pattern, pick, regex, relativeJsonPointer, string, time, uri, uriReference, uriTemplate, url, uuid };
//# sourceMappingURL=RandomGenerator.mjs.map |
Oops, I'm sorry, it was not a bug. |
Yeah I managed to do it |
@samchon |
Related to #1128
I fixed the import path of randexp