-
Notifications
You must be signed in to change notification settings - Fork 214
Allow Extensions to use .force_overrides @@W-18216861@@
#2380
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
Changes from 9 commits
5fd0b2b
a9d038f
fb9550e
f48a14b
7d38fc4
64067c4
56a7b32
a02fbf6
19dd0c9
e6b2789
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // DISCLAIMER | ||
| // | ||
| // BY USING THIS FILE, YOU AGREE THAT THE FUNCTIONALITY OF YOUR INSTALLED EXTENSION(S) IS NOT GUARANTEED. | ||
| // ADDITIONALLY UPGRADABILITY OF EXTENSIONS CAN ALSO NO LONGER BE GUARANTEED AND IS NOT SUPPORTED BY SALESFORCE. | ||
| // USE ONLY AS A TEMPORARY SOLUTION TO URGENTLY PATCH/UPDATE AN EXTENSION. | ||
| // | ||
| // USAGE: | ||
| // PLACE THE RELATIVE __POSIX__ PATH TO THE EXTENSION FILE YOU WANT TO OVERRIDE STARTING WITH THE EXTENSION PACKAGE NAME. | ||
| // MULTIPLE OVERRIDES CAN BE ADDED TO THIS FILE, ONE PER LINE. | ||
| // EXAMPLE: | ||
| // ./node_modules/@salesforce/extension-chakra-store-locator/src/components/content.tsx |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* | ||
| * Copyright (c) 2024, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| // Constants // TODO: Move to a shared location | ||
| export const LOCAL_EXTENSIONS_DIR = 'application-extensions' | ||
| export const EXTENSION_PACKAGE_PREFIX = 'extension-' | ||
| export const EXTENSION_PACKAGE_NAMESPACE = '@salesforce' | ||
| export const IMPORT_REGEX = /import\s+(?:(?:[\w*\s{},]*)\s+from\s+)?['"](\..*?)['"]/g | ||
| export const OVERRIDABLE_FILE_NAME = '.force_overrides' | ||
| export const MONO_REPO_WORKSPACE_FOLDER = 'packages' | ||
| export const NODE_MODULES_FOLDER = 'node_modules' | ||
| export const REQUIRES_REGEX = /require\(['"](\..*?)['"]\)/g | ||
| export const SRC_FOLDER = 'src' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,19 @@ | |
|
|
||
| // Third-Party | ||
| import dedent from 'dedent' | ||
| import fse from 'fs-extra' | ||
| import Handlebars from 'handlebars' | ||
| import path from 'path' | ||
|
|
||
| // Local | ||
| import {kebabToUpperCamelCase} from '../shared/utils' | ||
|
|
||
| // Types | ||
| import {ApplicationExtensionsLoaderOptions} from './webpack/types' | ||
| import type {ApplicationExtensionEntry} from '../types' | ||
|
|
||
| // Constants | ||
| import {LOCAL_EXTENSIONS_DIR, OVERRIDABLE_FILE_NAME, NODE_MODULES_FOLDER} from './constants' | ||
|
|
||
| // Register Handlebars helpers | ||
| Handlebars.registerHelper('getInstanceName', (aString: string) => { | ||
|
|
@@ -84,3 +90,58 @@ export const renderTemplate = (data: ApplicationExtensionsLoaderOptions) => { | |
| // Apply data to the compiled template | ||
| return template(data).trim() | ||
| } | ||
|
|
||
| /** | ||
| * @private | ||
| * Reads and parses a .force_overrides file into a list of clean override entries. | ||
| * - Skips empty lines | ||
| * - Skips full-line comments (`// comment`) | ||
| * - Supports inline comments (`override // comment`) | ||
| */ | ||
| export const getOverridesFromFile = (filePath: string): string[] => { | ||
| try { | ||
| const content = fse.readFileSync(filePath, 'utf8') | ||
| return content | ||
| .split(/\r?\n/) | ||
| .map((line) => line.trim()) | ||
| .filter((line) => line && !line.startsWith('//')) | ||
| .map((line) => line.split('//')[0].trim()) // remove inline comments | ||
| .filter(Boolean) | ||
|
Comment on lines
+104
to
+109
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is a line with only a comment on it, this filter ensures that the empty line isn't included. |
||
| } catch (e: any) { | ||
| if (e.code !== 'ENOENT') { | ||
| console.warn(`Error reading override file at ${filePath}:`, e) | ||
| } | ||
| return [] | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * PRIVATE: Returns a list of potential file paths where `.force_overrides` files might exist. | ||
| * | ||
| * These paths include: | ||
| * - A top-level `.force_overrides` file in the root of the project. | ||
| * - One per extension, prioritized with the local package version first. | ||
| * | ||
| * Note: | ||
| * - Each extension is assumed to be either a string or a tuple, where the first item is the extension name. | ||
| * - This function does not check if the files actually exist; it simply builds candidate paths. | ||
| * | ||
| * @param projectDir - The root directory of the project. | ||
| * @param extensions - A list of extension names or tuples where the first element is the extension name. | ||
| * @returns An array of string file paths to check for overrides. | ||
| */ | ||
| export const getForceOverridesFilePaths = ( | ||
| projectDir: string, | ||
| extensions: ApplicationExtensionEntry[] | ||
| ): string[] => { | ||
| return [ | ||
| path.join(projectDir, OVERRIDABLE_FILE_NAME), | ||
| ...extensions.flatMap((ext) => { | ||
| const name = typeof ext === 'string' ? ext : ext[0] | ||
| return [ | ||
| path.join(projectDir, LOCAL_EXTENSIONS_DIR, name, OVERRIDABLE_FILE_NAME), | ||
| path.join(projectDir, NODE_MODULES_FOLDER, name, OVERRIDABLE_FILE_NAME) | ||
| ] | ||
| }) | ||
| ] | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Do we want to update the script
npm run list-overridesto list the unused file override defined in the extensions .force-overrides?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.
Turns out that this script doesn't use the force-overrides directly. So we are going to create a new ticket for this once we get a better idea on the scope of the requirements.
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.
Ticket is created here --> https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07EE00002Dzrf2YAB/view