Skip to content

Commit 261d905

Browse files
committed
linting
1 parent 7fcbc16 commit 261d905

File tree

4 files changed

+82
-87
lines changed

4 files changed

+82
-87
lines changed

injected/entry-points/chrome.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import { isTrackerOrigin } from '../src/trackers';
55
import { computeLimitedSiteObject } from '../src/utils';
6-
import contentScopeFeatures from 'ddg:contentScopeFeatures'
6+
import contentScopeFeatures from 'ddg:contentScopeFeatures';
77

88
/**
99
* Inject all the overwrites into the page.
@@ -49,7 +49,9 @@ function init() {
4949
const reusableMethodName = '_rm' + randomString();
5050
const reusableSecret = '_r' + randomString();
5151
const siteObject = computeLimitedSiteObject();
52-
const initialScript = contentScopeFeatures + `
52+
const initialScript =
53+
contentScopeFeatures +
54+
`
5355
/* global contentScopeFeatures */
5456
contentScopeFeatures.load({
5557
platform: {

injected/scripts/entry-points.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bundle } from './utils/build.js'
1+
import { bundle } from './utils/build.js';
22
import { parseArgs, write } from '../../scripts/script-utils.js';
33

44
/**
@@ -59,31 +59,31 @@ const builds = {
5959
},
6060
};
6161

62-
async function init () {
62+
async function init() {
6363
// verify the input
64-
const requiredFields = []
65-
const args = parseArgs(process.argv.slice(2), requiredFields)
64+
const requiredFields = [];
65+
const args = parseArgs(process.argv.slice(2), requiredFields);
6666

6767
// if a platform was given as an argument, just build that platform
6868
if (args.platform) {
69-
const build = builds[args.platform]
69+
const build = builds[args.platform];
7070
if (!build) {
71-
throw new Error('unsupported platform: ' + args.platform)
71+
throw new Error('unsupported platform: ' + args.platform);
7272
}
73-
const output = await bundle({ scriptPath: build.input, platform: args.platform })
73+
const output = await bundle({ scriptPath: build.input, platform: args.platform });
7474

7575
// bundle and write the output
76-
write([build.output], output)
76+
write([build.output], output);
7777

78-
return
78+
return;
7979
}
8080

8181
// otherwise, just build them all
8282
for (const [injectName, build] of Object.entries(builds)) {
83-
const output = await bundle({ scriptPath: build.input, platform: injectName })
84-
write(build.output, output)
83+
const output = await bundle({ scriptPath: build.input, platform: injectName });
84+
write(build.output, output);
8585
console.log('✅', injectName, build.output[0]);
8686
}
8787
}
8888

89-
init()
89+
init();

injected/scripts/utils/build.js

Lines changed: 65 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { platformSupport } from '../../src/features.js'
2-
import { readFileSync } from 'fs'
3-
import { cwd } from '../../../scripts/script-utils.js'
4-
import { join } from 'path'
5-
import * as esbuild from 'esbuild'
6-
const ROOT = join(cwd(import.meta.url), '..', '..')
7-
const DEBUG = false
1+
import { platformSupport } from '../../src/features.js';
2+
import { readFileSync } from 'fs';
3+
import { cwd } from '../../../scripts/script-utils.js';
4+
import { join } from 'path';
5+
import * as esbuild from 'esbuild';
6+
const ROOT = join(cwd(import.meta.url), '..', '..');
7+
const DEBUG = false;
88

99
const contentScopePath = 'src/content-scope-features.js';
1010
const contentScopeName = 'contentScopeFeatures';
1111

12-
const prefixMessage = '/*! © DuckDuckGo ContentScopeScripts protections https://github.com/duckduckgo/content-scope-scripts/ */'
12+
const prefixMessage = '/*! © DuckDuckGo ContentScopeScripts protections https://github.com/duckduckgo/content-scope-scripts/ */';
1313

1414
/**
1515
* @param {object} params
@@ -19,23 +19,18 @@ const prefixMessage = '/*! © DuckDuckGo ContentScopeScripts protections https:/
1919
* @param {string} [params.name]
2020
* @return {Promise<string>}
2121
*/
22-
export async function bundle (params) {
23-
const {
24-
scriptPath,
25-
platform,
26-
name,
27-
featureNames,
28-
} = params
29-
30-
const extensions = ['firefox', 'chrome', 'chrome-mv3']
31-
const isExtension = extensions.includes(platform)
32-
let trackerLookup = '$TRACKER_LOOKUP$'
22+
export async function bundle(params) {
23+
const { scriptPath, platform, name, featureNames } = params;
24+
25+
const extensions = ['firefox', 'chrome', 'chrome-mv3'];
26+
const isExtension = extensions.includes(platform);
27+
let trackerLookup = '$TRACKER_LOOKUP$';
3328
if (!isExtension) {
34-
const trackerLookupData = readFileSync('../build/tracker-lookup.json', 'utf8')
35-
trackerLookup = trackerLookupData
29+
const trackerLookupData = readFileSync('../build/tracker-lookup.json', 'utf8');
30+
trackerLookup = trackerLookupData;
3631
}
37-
const suffixMessage = platform === 'firefox' ? `/*# sourceURL=duckduckgo-privacy-protection.js?scope=${name} */` : ''
38-
const loadFeaturesPlugin = loadFeatures(platform, featureNames)
32+
const suffixMessage = platform === 'firefox' ? `/*# sourceURL=duckduckgo-privacy-protection.js?scope=${name} */` : '';
33+
const loadFeaturesPlugin = loadFeatures(platform, featureNames);
3934
// The code is using a global, that we define here which means once tree shaken we get a browser specific output.
4035

4136
/** @type {import("esbuild").BuildOptions} */
@@ -50,34 +45,34 @@ export async function bundle (params) {
5045
globalName: name,
5146
loader: {
5247
'.css': 'text',
53-
'.svg': 'text'
48+
'.svg': 'text',
5449
},
5550
define: {
5651
'import.meta.env': 'development',
5752
'import.meta.injectName': JSON.stringify(platform),
58-
'import.meta.trackerLookup': trackerLookup
53+
'import.meta.trackerLookup': trackerLookup,
5954
},
6055
plugins: [loadFeaturesPlugin, contentFeaturesAsString(platform)],
6156
footer: {
62-
js: suffixMessage
57+
js: suffixMessage,
6358
},
6459
banner: {
65-
js: prefixMessage
66-
}
67-
}
60+
js: prefixMessage,
61+
},
62+
};
6863

69-
const result = await esbuild.build(buildOptions)
64+
const result = await esbuild.build(buildOptions);
7065

7166
if (result.metafile && DEBUG) {
72-
console.log(await esbuild.analyzeMetafile(result.metafile))
67+
console.log(await esbuild.analyzeMetafile(result.metafile));
7368
}
7469

7570
if (result.errors.length === 0 && result.outputFiles) {
76-
return result.outputFiles[0].text || ''
71+
return result.outputFiles[0].text || '';
7772
} else {
78-
console.log(result.errors)
79-
console.log(result.warnings)
80-
throw new Error('could not continue')
73+
console.log(result.errors);
74+
console.log(result.warnings);
75+
throw new Error('could not continue');
8176
}
8277
}
8378

@@ -88,78 +83,76 @@ export async function bundle (params) {
8883
* @param {string[]} featureNames
8984
* @returns {import("esbuild").Plugin}
9085
*/
91-
function loadFeatures (platform, featureNames = platformSupport[platform]) {
92-
const pluginId = 'ddg:platformFeatures'
86+
function loadFeatures(platform, featureNames = platformSupport[platform]) {
87+
const pluginId = 'ddg:platformFeatures';
9388
return {
9489
name: 'ddg:platformFeatures',
95-
setup (build) {
90+
setup(build) {
9691
build.onResolve({ filter: new RegExp(pluginId) }, (args) => {
9792
return {
9893
path: args.path,
99-
namespace: pluginId
100-
}
101-
})
94+
namespace: pluginId,
95+
};
96+
});
10297
build.onLoad({ filter: /.*/, namespace: pluginId }, () => {
10398
// convert a list of feature names to
10499
const imports = featureNames.map((featureName) => {
105-
const fileName = getFileName(featureName)
106-
const path = `./src/features/${fileName}.js`
107-
const ident = `ddg_feature_${featureName}`
100+
const fileName = getFileName(featureName);
101+
const path = `./src/features/${fileName}.js`;
102+
const ident = `ddg_feature_${featureName}`;
108103
return {
109104
ident,
110-
importPath: path
111-
}
112-
})
105+
importPath: path,
106+
};
107+
});
113108

114-
const importString = imports.map(imp => `import ${imp.ident} from ${JSON.stringify(imp.importPath)}`)
115-
.join(';\n')
109+
const importString = imports.map((imp) => `import ${imp.ident} from ${JSON.stringify(imp.importPath)}`).join(';\n');
116110

117-
const exportsString = imports.map(imp => `${imp.ident}`)
118-
.join(',\n ')
111+
const exportsString = imports.map((imp) => `${imp.ident}`).join(',\n ');
119112

120-
const exportString = `export default {\n ${exportsString}\n}`
113+
const exportString = `export default {\n ${exportsString}\n}`;
121114

122115
return {
123116
loader: 'js',
124117
resolveDir: ROOT,
125-
contents: [importString, exportString].join('\n')
126-
}
127-
})
128-
}
129-
}
118+
contents: [importString, exportString].join('\n'),
119+
};
120+
});
121+
},
122+
};
130123
}
131124

132-
function contentFeaturesAsString (platform) {
133-
const pluginId = 'ddg:contentScopeFeatures'
125+
function contentFeaturesAsString(platform) {
126+
const pluginId = 'ddg:contentScopeFeatures';
134127
return {
135128
/**
136129
* Load all platform features based on current
137130
*/
138131
name: pluginId,
139-
setup (build) {
132+
setup(build) {
140133
build.onResolve({ filter: new RegExp(pluginId) }, (args) => {
141134
return {
142135
path: args.path,
143-
namespace: pluginId
144-
}
145-
})
136+
namespace: pluginId,
137+
};
138+
});
146139
build.onLoad({ filter: /.*/, namespace: pluginId }, async () => {
147140
const result = await bundle({
148141
scriptPath: contentScopePath,
149142
name: contentScopeName,
150-
platform
151-
})
143+
platform,
144+
});
152145

153-
const encodedString = result.replace(/\r\n/g, '\n')
146+
const encodedString = result.replace(/\r\n/g, '\n');
154147

155148
return {
156149
loader: 'text',
157150
resolveDir: ROOT,
158-
contents: encodedString
159-
}
160-
})
161-
}
162-
}
151+
contents: encodedString,
152+
};
153+
});
154+
},
155+
};
163156
}
164157

165158
/**
@@ -170,4 +163,4 @@ function contentFeaturesAsString (platform) {
170163
*/
171164
function getFileName(featureName) {
172165
return featureName.replace(/([a-zA-Z])(?=[A-Z0-9])/g, '$1-').toLowerCase();
173-
}
166+
}

injected/src/globals.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ declare module 'ddg:platformFeatures' {
4848
export default output;
4949
}
5050
declare module 'ddg:contentScopeFeatures' {
51-
const output: string
51+
const output: string;
5252
export default output;
5353
}

0 commit comments

Comments
 (0)