Skip to content

Commit 65f1607

Browse files
committed
remove const declaration requirement
1 parent bdb7f25 commit 65f1607

File tree

8 files changed

+12
-49
lines changed

8 files changed

+12
-49
lines changed

.eslintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ module.exports = {
3232
'files': ['lib/**/*.ts', 'src/**/*.ts'],
3333
'excludedFiles': [
3434
'**/platform_support.ts',
35-
'**/common_exports.ts',
36-
'**/export_types.ts',
3735
'**/*.spec.ts',
3836
'**/*.test.ts',
3937
'**/*.tests.ts',

.platform-isolation.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ module.exports = {
1515
exclude: [
1616
// Platform definition file (this file defines Platform type, doesn't need __platforms)
1717
'**/platform_support.ts',
18-
19-
// '**/common_exports.ts',
20-
// '**/export_types.ts',
2118

2219
// Test files
2320
'**/*.spec.ts',

eslint-local-rules/require-platform-declaration.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ module.exports = {
4646
},
4747
messages: {
4848
missingPlatformDeclaration: 'File must export __platforms to declare which platforms it supports. Example: export const __platforms = [\'__universal__\'];',
49-
invalidPlatformDeclaration: '__platforms must be exported as a const array. Example: export const __platforms = [\'browser\', \'node\'];',
50-
invalidPlatformValue: '__platforms contains invalid platform value "{{value}}". Valid platforms are: {{validPlatforms}}',
51-
emptyPlatformArray: '__platforms array cannot be empty. Specify at least one platform or use [\'__universal__\']',
49+
notArray: '__platforms must be an array literal. Example: export const __platforms = [\'browser\', \'node\'];',
50+
emptyArray: '__platforms array cannot be empty. Specify at least one platform or use [\'__universal__\'].',
51+
notLiterals: '__platforms must only contain string literals. Do NOT use variables, computed values, or spread operators.',
52+
invalidValues: 'Invalid platform value "{{value}}". Valid platforms are: {{validPlatforms}}',
5253
},
5354
schema: [],
5455
},
@@ -69,15 +70,6 @@ module.exports = {
6970

7071
hasPlatformExport = true;
7172

72-
// Validate it's a const
73-
if (node.declaration.kind !== 'const') {
74-
context.report({
75-
node: declarator,
76-
messageId: 'invalidPlatformDeclaration',
77-
});
78-
return;
79-
}
80-
8173
// Validate it's an array expression
8274
let init = declarator.init;
8375

@@ -94,7 +86,7 @@ module.exports = {
9486
if (!init || init.type !== 'ArrayExpression') {
9587
context.report({
9688
node: declarator,
97-
messageId: 'invalidPlatformDeclaration',
89+
messageId: 'notArray',
9890
});
9991
return;
10092
}
@@ -103,7 +95,7 @@ module.exports = {
10395
if (init.elements.length === 0) {
10496
context.report({
10597
node: init,
106-
messageId: 'emptyPlatformArray',
98+
messageId: 'emptyArray',
10799
});
108100
return;
109101
}
@@ -114,7 +106,7 @@ module.exports = {
114106
if (!VALID_PLATFORMS.includes(element.value)) {
115107
context.report({
116108
node: element,
117-
messageId: 'invalidPlatformValue',
109+
messageId: 'invalidValues',
118110
data: {
119111
value: element.value,
120112
validPlatforms: VALID_PLATFORMS.map(p => `'${p}'`).join(', ')
@@ -125,7 +117,7 @@ module.exports = {
125117
// Not a string literal
126118
context.report({
127119
node: element || init,
128-
messageId: 'invalidPlatformDeclaration',
120+
messageId: 'notLiterals',
129121
});
130122
}
131123
}

lib/utils/http_request_handler/request_handler.browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,4 @@ export class BrowserRequestHandler implements RequestHandler {
134134
}
135135
}
136136

137-
export const __platforms: Platform[] = ['browser'];
137+
export const __platforms: Platform[] = ['browser', 'react_native'];

message_generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const generate = async () => {
1818
let genOut = '';
1919

2020
Object.keys(exports).forEach((key, i) => {
21-
if (key === 'messages') return;
21+
if (key === 'messages' || key === '__platforms') return;
2222
genOut += `export const ${key} = '${i}';\n`;
2323
messages.push(exports[key])
2424
});

scripts/add-platform-exports.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ function processFile(filePath) {
296296

297297
// Extract platforms and error info from result
298298
const existingPlatforms = result.success ? result.platforms : null;
299-
const needsFixing = result.error && ['MISSING', 'NOT_CONST', 'NOT_ARRAY', 'EMPTY_ARRAY', 'NOT_LITERALS', 'INVALID_VALUES'].includes(result.error.type);
299+
const needsFixing = result.error && ['MISSING', 'NOT_ARRAY', 'EMPTY_ARRAY', 'NOT_LITERALS', 'INVALID_VALUES'].includes(result.error.type);
300300

301301
// Determine platforms for this file
302302
// If file already has valid platforms, use those (preserve existing values)
@@ -315,7 +315,7 @@ function processFile(filePath) {
315315
let action = 'skipped';
316316

317317
if (needsFixing) {
318-
// Has issues (MISSING, NOT_CONST, NOT_LITERALS, INVALID_VALUES, etc.), fix them
318+
// Has issues (MISSING, NOT_ARRAY, NOT_LITERALS, INVALID_VALUES, etc.), fix them
319319
const extracted = extractExistingPlatformExport(content, filePath);
320320
if (extracted.removed) {
321321
content = extracted.content;

scripts/platform-utils.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ function getValidPlatforms(workspaceRoot) {
9999
*/
100100
function extractPlatformsFromAST(sourceFile, filePath, validPlatforms) {
101101
let found = false;
102-
let isConst = false;
103102
let isArray = false;
104103
let platforms = [];
105104
let hasNonStringLiteral = false;
@@ -113,15 +112,12 @@ function extractPlatformsFromAST(sourceFile, filePath, validPlatforms) {
113112
);
114113

115114
if (hasExport) {
116-
const isConstDecl = (node.declarationList.flags & ts.NodeFlags.Const) !== 0;
117-
118115
for (const declaration of node.declarationList.declarations) {
119116
if (ts.isVariableDeclaration(declaration) &&
120117
ts.isIdentifier(declaration.name) &&
121118
declaration.name.text === '__platforms') {
122119

123120
found = true;
124-
isConst = isConstDecl;
125121

126122
let initializer = declaration.initializer;
127123

@@ -172,16 +168,6 @@ function extractPlatformsFromAST(sourceFile, filePath, validPlatforms) {
172168
};
173169
}
174170

175-
if (!isConst) {
176-
return {
177-
success: false,
178-
error: {
179-
type: 'NOT_CONST',
180-
message: `'__platforms' must be declared with 'const', found non-const declaration`
181-
}
182-
};
183-
}
184-
185171
if (!isArray) {
186172
return {
187173
success: false,

scripts/validate-platform-isolation-ts.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ function main() {
441441
// Group errors by type
442442
const errorsByType = {
443443
MISSING: [],
444-
NOT_CONST: [],
445444
NOT_ARRAY: [],
446445
EMPTY_ARRAY: [],
447446
NOT_LITERALS: [],
@@ -467,15 +466,6 @@ function main() {
467466
console.error(`\n${errorsByType.MISSING[0].error.message}\n`);
468467
}
469468

470-
if (errorsByType.NOT_CONST.length > 0) {
471-
hasErrors = true;
472-
console.error(`❌ Found ${errorsByType.NOT_CONST.length} file(s) with __platforms not declared as const:\n`);
473-
for (const { filePath, error } of errorsByType.NOT_CONST) {
474-
console.error(` 📄 ${path.relative(process.cwd(), filePath)}`);
475-
}
476-
console.error(`\n${errorsByType.NOT_CONST[0].error.message}\n`);
477-
}
478-
479469
if (errorsByType.NOT_ARRAY.length > 0) {
480470
hasErrors = true;
481471
console.error(`❌ Found ${errorsByType.NOT_ARRAY.length} file(s) with __platforms not declared as an array:\n`);

0 commit comments

Comments
 (0)