Skip to content

Commit

Permalink
Back to 8 character hashes with base-64 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Sep 4, 2022
1 parent 9474ba5 commit 58c03c5
Show file tree
Hide file tree
Showing 358 changed files with 403 additions and 401 deletions.
2 changes: 1 addition & 1 deletion src/utils/base64.ts
Expand Up @@ -5,7 +5,7 @@ export function toBase64(num: number): string {
let outStr = '';
do {
const curDigit = num % base;
num = Math.floor(num / base);
num = (num / base) | 0;
outStr = chars[curDigit] + outStr;
} while (num !== 0);
return outStr;
Expand Down
12 changes: 7 additions & 5 deletions src/utils/hashPlaceholders.ts
@@ -1,13 +1,14 @@
import { toBase64 } from './base64';
import { errFailedValidation, error } from './error';

// Four random characters from the private use area to minimize risk of conflicts
const hashPlaceholderLeft = '_!~{';
const hashPlaceholderLeft = '!~{';
const hashPlaceholderRight = '}~';
const hashPlaceholderOverhead = hashPlaceholderLeft.length + hashPlaceholderRight.length;

// This is the size of a sha256
export const maxHashSize = 64;
export const defaultHashSize = 9;
export const defaultHashSize = 8;

export type HashPlaceholderGenerator = (optionName: string, hashSize?: number) => string;

Expand All @@ -21,7 +22,7 @@ export const getHashPlaceholderGenerator = (): HashPlaceholderGenerator => {
)
);
}
const placeholder = `${hashPlaceholderLeft}${String(++nextIndex).padStart(
const placeholder = `${hashPlaceholderLeft}${toBase64(++nextIndex).padStart(
hashSize - hashPlaceholderOverhead,
'0'
)}${hashPlaceholderRight}`;
Expand All @@ -32,13 +33,14 @@ export const getHashPlaceholderGenerator = (): HashPlaceholderGenerator => {
)
);
}
nextIndex++;
return placeholder;
};
};

const REPLACER_REGEX = new RegExp(
`${hashPlaceholderLeft}\\d{1,${maxHashSize - hashPlaceholderOverhead}}${hashPlaceholderRight}`,
`${hashPlaceholderLeft}[0-9a-zA-Z_$]{1,${
maxHashSize - hashPlaceholderOverhead
}}${hashPlaceholderRight}`,
'g'
);

Expand Down
@@ -0,0 +1,3 @@
import { foo } from './dep-bd733981.js';

console.log(foo);

This file was deleted.

@@ -0,0 +1,10 @@
define(['exports', './foo-amd-0f9dc16c', './nested/bar-amd-f038b10c', './nested/baz-amd-d3de4cc0', './no-ext-amd-9d2c6ef6'], (function (exports, foo, bar, baz, noExt) { 'use strict';



exports.foo = foo;
exports.bar = bar;
exports.baz = baz;
exports.noExt = noExt;

}));

This file was deleted.

This file was deleted.

@@ -0,0 +1,13 @@
'use strict';

var foo = require('./foo-cjs-0d5774b5.js');
var bar = require('./nested/bar-cjs-abedc91d.js');
var baz = require('./nested/baz-cjs-4a9c02fc.js');
var noExt = require('./no-ext-cjs-500f8f81.js');



exports.foo = foo;
exports.bar = bar;
exports.baz = baz;
exports.noExt = noExt;

This file was deleted.

@@ -0,0 +1,4 @@
export { default as foo } from './foo-es-3585f3eb.js';
export { default as bar } from './nested/bar-es-bd5e2ae1.js';
export { default as baz } from './nested/baz-es-a913ab4d.js';
export { default as noExt } from './no-ext-es-1f34b6e8.js';
@@ -1,4 +1,4 @@
System.register(['./foo-system-0e2d8e488.js', './nested/bar-system-a72f6c959.js', './nested/baz-system-71d114fda.js', './no-ext-system-0cf938a89.js'], (function (exports) {
System.register(['./foo-system-0e2d8e48.js', './nested/bar-system-a72f6c95.js', './nested/baz-system-71d114fd.js', './no-ext-system-0cf938a8.js'], (function (exports) {
'use strict';
return {
setters: [function (module) {
Expand Down
@@ -1,6 +1,6 @@
define(['require'], (function (require) { 'use strict';

console.log('main');
new Promise(function (resolve, reject) { require(['./chunk-deb-87ce45a94-amd'], resolve, reject); }).then(console.log);
new Promise(function (resolve, reject) { require(['./chunk-deb-87ce45a9-amd'], resolve, reject); }).then(console.log);

}));
@@ -1,4 +1,4 @@
'use strict';

console.log('main');
Promise.resolve().then(function () { return require('./chunk-deb-699056073-cjs.js'); }).then(console.log);
Promise.resolve().then(function () { return require('./chunk-deb-69905607-cjs.js'); }).then(console.log);
@@ -0,0 +1,2 @@
console.log('main');
import('./chunk-deb-9f85baf7-es.js').then(console.log);

This file was deleted.

Expand Up @@ -4,7 +4,7 @@ System.register([], (function (exports, module) {
execute: (function () {

console.log('main');
module.import('./chunk-deb-467d682b3-system.js').then(console.log);
module.import('./chunk-deb-467d682b-system.js').then(console.log);

})
};
Expand Down
@@ -1,6 +1,6 @@
define(['require', 'exports'], (function (require, exports) { 'use strict';

var logo = new URL(require.toUrl('./assets/logo1-60bc15c4c.svg'), document.baseURI).href;
var logo = new URL(require.toUrl('./assets/logo1-60bc15c4.svg'), document.baseURI).href;

function showImage(url) {
console.log(url);
Expand Down
@@ -1,6 +1,6 @@
define(['require', '../main'], (function (require, main) { 'use strict';

var logo = new URL(require.toUrl('../assets/logo2-fdaa74783.svg'), document.baseURI).href;
var logo = new URL(require.toUrl('../assets/logo2-fdaa7478.svg'), document.baseURI).href;

main.showImage(logo);

Expand Down
@@ -1,6 +1,6 @@
'use strict';

var logo = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/logo1-60bc15c4c.svg').href : new URL('assets/logo1-60bc15c4c.svg', document.currentScript && document.currentScript.src || document.baseURI).href);
var logo = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/logo1-60bc15c4.svg').href : new URL('assets/logo1-60bc15c4.svg', document.currentScript && document.currentScript.src || document.baseURI).href);

function showImage(url) {
console.log(url);
Expand Down
Expand Up @@ -2,6 +2,6 @@

var main = require('../main.js');

var logo = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/../assets/logo2-fdaa74783.svg').href : new URL('../assets/logo2-fdaa74783.svg', document.currentScript && document.currentScript.src || document.baseURI).href);
var logo = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/../assets/logo2-fdaa7478.svg').href : new URL('../assets/logo2-fdaa7478.svg', document.currentScript && document.currentScript.src || document.baseURI).href);

main.showImage(logo);
@@ -1,4 +1,4 @@
var logo = new URL('assets/logo1-60bc15c4c.svg', import.meta.url).href;
var logo = new URL('assets/logo1-60bc15c4.svg', import.meta.url).href;

function showImage(url) {
console.log(url);
Expand Down
@@ -1,5 +1,5 @@
import { s as showImage } from '../main.js';

var logo = new URL('../assets/logo2-fdaa74783.svg', import.meta.url).href;
var logo = new URL('../assets/logo2-fdaa7478.svg', import.meta.url).href;

showImage(logo);
Expand Up @@ -5,7 +5,7 @@ System.register([], (function (exports, module) {

exports('s', showImage);

var logo = new URL('assets/logo1-60bc15c4c.svg', module.meta.url).href;
var logo = new URL('assets/logo1-60bc15c4.svg', module.meta.url).href;

function showImage(url) {
console.log(url);
Expand Down
Expand Up @@ -7,7 +7,7 @@ System.register(['../main.js'], (function (exports, module) {
}],
execute: (function () {

var logo = new URL('../assets/logo2-fdaa74783.svg', module.meta.url).href;
var logo = new URL('../assets/logo2-fdaa7478.svg', module.meta.url).href;

showImage(logo);

Expand Down
@@ -0,0 +1 @@
generateBundle amd with assets/generateBundle-format-240389f4.txt

This file was deleted.

@@ -1 +1 @@
generateBundle amd with assets/generateBundle-format-240389f4b.txt
generateBundle amd with assets/generateBundle-format-240389f4.txt
@@ -1,6 +1,6 @@
define(['require', 'exports'], (function (require, exports) { 'use strict';

const renderStart = new URL(require.toUrl('./assets/renderStart-981aa2ea6.txt'), document.baseURI).href;
const renderStart = new URL(require.toUrl('./assets/renderStart-981aa2ea.txt'), document.baseURI).href;
const renderStartNamed = new URL(require.toUrl('./renderStart.txt'), document.baseURI).href;
const renderStartNamedImmediately = 'renderStart.txt';
const bannerNamed = new URL(require.toUrl('./banner.txt'), document.baseURI).href;
Expand Down

This file was deleted.

@@ -0,0 +1 @@
generateBundle cjs with assets/generateBundle-format-4efb05bc.txt
@@ -1 +1 @@
generateBundle cjs with assets/generateBundle-format-4efb05bcf.txt
generateBundle cjs with assets/generateBundle-format-4efb05bc.txt
@@ -1,6 +1,6 @@
'use strict';

const renderStart = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/renderStart-981aa2ea6.txt').href : new URL('assets/renderStart-981aa2ea6.txt', document.currentScript && document.currentScript.src || document.baseURI).href);
const renderStart = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/renderStart-981aa2ea.txt').href : new URL('assets/renderStart-981aa2ea.txt', document.currentScript && document.currentScript.src || document.baseURI).href);
const renderStartNamed = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/renderStart.txt').href : new URL('renderStart.txt', document.currentScript && document.currentScript.src || document.baseURI).href);
const renderStartNamedImmediately = 'renderStart.txt';
const bannerNamed = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/banner.txt').href : new URL('banner.txt', document.currentScript && document.currentScript.src || document.baseURI).href);
Expand Down
@@ -0,0 +1 @@
generateBundle es with assets/generateBundle-format-c0bc1e08.txt

This file was deleted.

@@ -1 +1 @@
generateBundle es with assets/generateBundle-format-c0bc1e08f.txt
generateBundle es with assets/generateBundle-format-c0bc1e08.txt
@@ -1,4 +1,4 @@
const renderStart = new URL('assets/renderStart-981aa2ea6.txt', import.meta.url).href;
const renderStart = new URL('assets/renderStart-981aa2ea.txt', import.meta.url).href;
const renderStartNamed = new URL('renderStart.txt', import.meta.url).href;
const renderStartNamedImmediately = 'renderStart.txt';
const bannerNamed = new URL('banner.txt', import.meta.url).href;
Expand Down
@@ -1 +1 @@
generateBundle system with assets/generateBundle-format-bbc5e661e.txt
generateBundle system with assets/generateBundle-format-bbc5e661.txt
@@ -1 +1 @@
generateBundle system with assets/generateBundle-format-bbc5e661e.txt
generateBundle system with assets/generateBundle-format-bbc5e661.txt
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports, module) {
return {
execute: (function () {

const renderStart = exports('renderStart', new URL('assets/renderStart-981aa2ea6.txt', module.meta.url).href);
const renderStart = exports('renderStart', new URL('assets/renderStart-981aa2ea.txt', module.meta.url).href);
const renderStartNamed = exports('renderStartNamed', new URL('renderStart.txt', module.meta.url).href);
const renderStartNamedImmediately = exports('renderStartNamedImmediately', 'renderStart.txt');
const bannerNamed = exports('bannerNamed', new URL('banner.txt', module.meta.url).href);
Expand Down

This file was deleted.

@@ -0,0 +1,5 @@
define(['./chunk-main2-a7baadb6-amd'], (function (main2) { 'use strict';

main2.log(main2.dep);

}));
@@ -0,0 +1,7 @@
define(['./chunk-main2-a7baadb6-amd'], (function (main2) { 'use strict';



return main2.log;

}));

This file was deleted.

@@ -0,0 +1,5 @@
'use strict';

var main2 = require('./chunk-main2-399c15fc-cjs.js');

main2.log(main2.dep);

This file was deleted.

This file was deleted.

@@ -0,0 +1,7 @@
'use strict';

var main2 = require('./chunk-main2-399c15fc-cjs.js');



module.exports = main2.log;
@@ -0,0 +1,3 @@
import { l as log, d as dep } from './chunk-main2-c42fce1a-es.js';

log(dep);

This file was deleted.

@@ -0,0 +1 @@
export { l as default } from './chunk-main2-c42fce1a-es.js';

This file was deleted.

@@ -1,4 +1,4 @@
System.register(['./chunk-main2-9cc036248-system.js'], (function () {
System.register(['./chunk-main2-9cc03624-system.js'], (function () {
'use strict';
var log, dep;
return {
Expand Down
@@ -1,4 +1,4 @@
System.register(['./chunk-main2-9cc036248-system.js'], (function (exports) {
System.register(['./chunk-main2-9cc03624-system.js'], (function (exports) {
'use strict';
return {
setters: [function (module) {
Expand Down
2 changes: 1 addition & 1 deletion test/chunking-form/samples/hashing/random-match/_config.js
Expand Up @@ -2,7 +2,7 @@ module.exports = {
description: 'leaves random hash matches untransformed',
options: {
output: {
entryFileNames: 'entry-[hash]-_!~{0001}~-_!~{1234}~.js'
entryFileNames: 'entry-[hash]-!~{001}~-!~{123}~.js'
}
}
};
@@ -0,0 +1,6 @@
define((function () { 'use strict';

console.log('replaced: a38385ce');
console.log('not replaced: !~{123}~');

}));

This file was deleted.

@@ -0,0 +1,4 @@
'use strict';

console.log('replaced: 55937672');
console.log('not replaced: !~{123}~');

0 comments on commit 58c03c5

Please sign in to comment.