Skip to content

Commit

Permalink
Add semicolons (prettier)
Browse files Browse the repository at this point in the history
  • Loading branch information
muodov committed Nov 5, 2024
1 parent 14b925a commit 680984a
Show file tree
Hide file tree
Showing 357 changed files with 11,596 additions and 11,591 deletions.
110 changes: 55 additions & 55 deletions .github/scripts/diff-directories.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import fs from 'fs'
import path from 'path'
import fs from 'fs';
import path from 'path';

function readFilesRecursively(directory) {
const filenames = fs.readdirSync(directory)
const files = {}
const filenames = fs.readdirSync(directory);
const files = {};

filenames.forEach((filename) => {
const filePath = path.join(directory, filename)
const fileStats = fs.statSync(filePath)
const filePath = path.join(directory, filename);
const fileStats = fs.statSync(filePath);

if (fileStats.isDirectory()) {
const nestedFiles = readFilesRecursively(filePath)
const nestedFiles = readFilesRecursively(filePath);
for (const [nestedFilePath, nestedFileContent] of Object.entries(nestedFiles)) {
files[path.join(filename, nestedFilePath)] = nestedFileContent
files[path.join(filename, nestedFilePath)] = nestedFileContent;
}
} else {
files[filename] = fs.readFileSync(filePath, 'utf-8')
files[filename] = fs.readFileSync(filePath, 'utf-8');
}
})
});

return files
return files;
}

function upperCaseFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1)
return string.charAt(0).toUpperCase() + string.slice(1);
}

function displayDiffs(dir1Files, dir2Files, isOpen) {
const rollupGrouping = {}
const rollupGrouping = {};
/**
* Rolls up multiple files with the same diff into a single entry
* @param {string} fileName
Expand All @@ -36,89 +36,89 @@ function displayDiffs(dir1Files, dir2Files, isOpen) {
*/
function add(fileName, string, summary = undefined) {
if (summary === undefined) {
summary = string
summary = string;
}
if (!(summary in rollupGrouping)) {
rollupGrouping[summary] = { files: [] }
rollupGrouping[summary] = { files: [] };
}
rollupGrouping[summary].files.push(fileName)
rollupGrouping[summary].string = string
rollupGrouping[summary].files.push(fileName);
rollupGrouping[summary].string = string;
}
for (const [filePath, fileContent] of Object.entries(dir1Files)) {
let diffOut = ''
let compareOut
let diffOut = '';
let compareOut;
if (filePath in dir2Files) {
const fileOut = fileContent
const file2Out = dir2Files[filePath]
delete dir2Files[filePath]
const fileOut = fileContent;
const file2Out = dir2Files[filePath];
delete dir2Files[filePath];
if (fileOut === file2Out) {
continue
continue;
} else {
compareOut = filePath.split('/')[0]
diffOut = `File has changed`
compareOut = filePath.split('/')[0];
diffOut = `File has changed`;
}
} else {
diffOut = '❌ File only exists in old changeset'
compareOut = 'Removed Files'
diffOut = '❌ File only exists in old changeset';
compareOut = 'Removed Files';
}
add(filePath, diffOut, compareOut)
add(filePath, diffOut, compareOut);
}

for (const filePath of Object.keys(dir2Files)) {
add(filePath, '❌ File only exists in new changeset', 'New Files')
add(filePath, '❌ File only exists in new changeset', 'New Files');
}
const outString = Object.keys(rollupGrouping)
.map((key) => {
const rollup = rollupGrouping[key]
const rollup = rollupGrouping[key];
let outString = `
`
const title = key
`;
const title = key;
if (rollup.files.length) {
for (const file of rollup.files) {
outString += `- ${file}\n`
outString += `- ${file}\n`;
}
}
outString += '\n\n' + rollup.string
return renderDetails(title, outString, isOpen)
outString += '\n\n' + rollup.string;
return renderDetails(title, outString, isOpen);
})
.join('\n')
return outString
.join('\n');
return outString;
}

function renderDetails(section, text, isOpen) {
if (section === 'dist') {
section = 'apple'
section = 'apple';
}
const open = section !== 'integration' ? 'open' : ''
const open = section !== 'integration' ? 'open' : '';
return `<details ${open}>
<summary>${upperCaseFirstLetter(section)}</summary>
${text}
</details>`
</details>`;
}

if (process.argv.length !== 4) {
console.error('Usage: node diff_directories.js <directory1> <directory2>')
process.exit(1)
console.error('Usage: node diff_directories.js <directory1> <directory2>');
process.exit(1);
}

const dir1 = process.argv[2]
const dir2 = process.argv[3]
const dir1 = process.argv[2];
const dir2 = process.argv[3];

const sections = {}
const sections = {};
function sortFiles(dirFiles, dirName) {
for (const [filePath, fileContent] of Object.entries(dirFiles)) {
sections[dirName] = sections[dirName] || {}
sections[dirName][filePath] = fileContent
sections[dirName] = sections[dirName] || {};
sections[dirName][filePath] = fileContent;
}
}

const buildDir = '/build'
const sourcesOutput = '/Sources/ContentScopeScripts/'
sortFiles(readFilesRecursively(dir1 + buildDir), 'dir1')
sortFiles(readFilesRecursively(dir2 + buildDir), 'dir2')
sortFiles(readFilesRecursively(dir1 + sourcesOutput), 'dir1')
sortFiles(readFilesRecursively(dir2 + sourcesOutput), 'dir2')
const buildDir = '/build';
const sourcesOutput = '/Sources/ContentScopeScripts/';
sortFiles(readFilesRecursively(dir1 + buildDir), 'dir1');
sortFiles(readFilesRecursively(dir2 + buildDir), 'dir2');
sortFiles(readFilesRecursively(dir1 + sourcesOutput), 'dir1');
sortFiles(readFilesRecursively(dir2 + sourcesOutput), 'dir2');

// console.log(Object.keys(files))
const fileOut = displayDiffs(sections.dir1, sections.dir2, true)
console.log(fileOut)
const fileOut = displayDiffs(sections.dir1, sections.dir2, true);
console.log(fileOut);
2 changes: 1 addition & 1 deletion build-output.eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export default [
'no-implicit-globals': 'error',
},
},
]
];
8 changes: 4 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tseslint from 'typescript-eslint'
import ddgConfig from '@duckduckgo/eslint-config'
import globals from 'globals'
import tseslint from 'typescript-eslint';
import ddgConfig from '@duckduckgo/eslint-config';
import globals from 'globals';

// @ts-check
export default tseslint.config(
Expand Down Expand Up @@ -108,4 +108,4 @@ export default tseslint.config(
},
},
},
)
);
28 changes: 14 additions & 14 deletions injected/entry-points/android.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/**
* @module Android integration
*/
import { load, init } from '../src/content-scope-features.js'
import { processConfig, isGloballyDisabled } from './../src/utils'
import { isTrackerOrigin } from '../src/trackers'
import { AndroidMessagingConfig } from '../../messaging/index.js'
import { load, init } from '../src/content-scope-features.js';
import { processConfig, isGloballyDisabled } from './../src/utils';
import { isTrackerOrigin } from '../src/trackers';
import { AndroidMessagingConfig } from '../../messaging/index.js';

function initCode() {
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$)
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$);
if (isGloballyDisabled(processedConfig)) {
return
return;
}

const configConstruct = processedConfig
const messageCallback = configConstruct.messageCallback
const messageSecret = configConstruct.messageSecret
const javascriptInterface = configConstruct.javascriptInterface
const configConstruct = processedConfig;
const messageCallback = configConstruct.messageCallback;
const messageSecret = configConstruct.messageSecret;
const javascriptInterface = configConstruct.javascriptInterface;
processedConfig.messagingConfig = new AndroidMessagingConfig({
messageSecret,
messageCallback,
javascriptInterface,
target: globalThis,
debug: processedConfig.debug,
})
});

load({
platform: processedConfig.platform,
Expand All @@ -32,9 +32,9 @@ function initCode() {
site: processedConfig.site,
bundledConfig: processedConfig.bundledConfig,
messagingConfig: processedConfig.messagingConfig,
})
});

init(processedConfig)
init(processedConfig);
}

initCode()
initCode();
24 changes: 12 additions & 12 deletions injected/entry-points/apple.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/**
* @module Apple integration
*/
import { load, init } from '../src/content-scope-features.js'
import { processConfig, isGloballyDisabled } from './../src/utils'
import { isTrackerOrigin } from '../src/trackers'
import { WebkitMessagingConfig, TestTransportConfig } from '../../messaging/index.js'
import { load, init } from '../src/content-scope-features.js';
import { processConfig, isGloballyDisabled } from './../src/utils';
import { isTrackerOrigin } from '../src/trackers';
import { WebkitMessagingConfig, TestTransportConfig } from '../../messaging/index.js';

function initCode() {
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$)
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$);
if (isGloballyDisabled(processedConfig)) {
return
return;
}

if (import.meta.injectName === 'apple-isolated') {
processedConfig.messagingConfig = new WebkitMessagingConfig({
webkitMessageHandlerNames: ['contentScopeScriptsIsolated'],
secret: '',
hasModernWebkitAPI: true,
})
});
} else {
processedConfig.messagingConfig = new TestTransportConfig({
notify() {
Expand All @@ -30,9 +30,9 @@ function initCode() {
subscribe() {
return () => {
// noop
}
};
},
})
});
}

load({
Expand All @@ -42,12 +42,12 @@ function initCode() {
site: processedConfig.site,
bundledConfig: processedConfig.bundledConfig,
messagingConfig: processedConfig.messagingConfig,
})
});

init(processedConfig)
init(processedConfig);

// Not supported:
// update(message)
}

initCode()
initCode();
28 changes: 14 additions & 14 deletions injected/entry-points/chrome-mv3.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* @module Chrome MV3 integration
*/
import { load, init, update } from '../src/content-scope-features.js'
import { isTrackerOrigin } from '../src/trackers'
import { computeLimitedSiteObject } from '../src/utils.js'
import { load, init, update } from '../src/content-scope-features.js';
import { isTrackerOrigin } from '../src/trackers';
import { computeLimitedSiteObject } from '../src/utils.js';

const secret = (crypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32).toString().replace('0.', '')
const secret = (crypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32).toString().replace('0.', '');

const trackerLookup = import.meta.trackerLookup
const trackerLookup = import.meta.trackerLookup;

load({
platform: {
Expand All @@ -18,27 +18,27 @@ load({
site: computeLimitedSiteObject(),
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
bundledConfig: $BUNDLED_CONFIG$,
})
});

// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
window.addEventListener(secret, ({ detail: message }) => {
if (!message) return
if (!message) return;

switch (message.type) {
case 'update':
update(message)
break
update(message);
break;
case 'register':
if (message.argumentsObject) {
message.argumentsObject.messageSecret = secret
init(message.argumentsObject)
message.argumentsObject.messageSecret = secret;
init(message.argumentsObject);
}
break
break;
}
})
});

window.dispatchEvent(
new CustomEvent('ddg-secret', {
detail: secret,
}),
)
);
Loading

0 comments on commit 680984a

Please sign in to comment.