-
Notifications
You must be signed in to change notification settings - Fork 48
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
PDCL-10688 - Support custom builds using the npm package #1087
Conversation
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.
I haven't been following this work too closely, so I'm a bit late to this. All of these comments could be addressed in a separate ticket.
} | ||
} | ||
}; | ||
}; |
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.
One of the goals of this project is to get Adobe Tags to support this build method. To that end whatever thing we make could be used by other Tags extension developers. There is a lot of specific logic inside of the conditionalBuildBabelPlugin code that only applies to our specific use-case. For example, when I see a directive named @skipwhen it makes me think I could put this in front of anything; however, from this code it looks like you could only use it in front of an import and also if you are using the variable in an array.
I did a bit of research about conditionally building things in javascript. One of the established patterns within javascript libraries is to use an if statement that references process.env. This is especially used when referencing process.env.NODE_ENV. i.e.
if (process.env.NODE_ENV === "development") {
console.log("development mode!");
}
I put together a sample to see if this would work with Rollup. I've also noticed that a lot of rollup systems have plugins or ways to accomplish this. https://github.com/jonsnyder/conditional-compilation-sample
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.
Good point @jonsnyder!
@shammowla Please check out Jon's sample and maybe let's schedule a work session to make this PR more reusable.
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.
I believe that the Babel plugin was from @dompuiu, so it may have something to do with how he envisions Launch support will happen i.e. furance/forge will run Babel but not rollup.
scripts/helpers/componentNames.js
Outdated
exportName: "createMachineLearning", | ||
filePath: "MachineLearning" | ||
} | ||
]; |
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.
Like Joe has mentioned, I don't like having to update this file anytime we create a new component. One way we could do this is import "src/core/componentCreators.js" within scripts. To do this we'd have to make sure we are using Node version >= 13 because currently scripts are written with require and the rest of the code is written with import. Ideally we should move all the code to use import and require a version of Node that supports it. Then we could loop through the component array and grab the name of each one.
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.
Deleted the componentNames.js and dynamically creating the list from componentCreators. customBuild.js script reads componentCreators.js, uses a regular expression to find all occurrences of create followed by an uppercase letter and any number of word characters (which should match the names of the component creator functions), formats the component names for export, and writes them to componentNames.js.
scripts/helpers/customBuild.js
Outdated
"identity", | ||
"datacollector", | ||
"libraryinfo" | ||
]; |
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.
I don't think any component should be "untouchable". If there is some logic that is untouchable it should be incorporated into core. Some of these components will need some work to make that a reality.
- context - This could be removed except for the fact that it handles adding a timestamp and implementationInfo to the XDM. This functionality should be put into core.
- privacy - I believe you can leave this out now without any problems. I see this being a big use case for customers too if they don't ever use consent.
- identity - I can see a customer wanting to remove this if they use FPID. I think the library would work without identity right now.
- datacollector - Currently this component defines "sendEvent" command. We should probably make "sendEvent" command part of core, and then each component can apply its own logic via onBeforeEvent lifecycle hook.
- libraryinfo - We could make this part of core.
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.
@jonsnyder Do you think we should do this before carrying on with the custom build task?
console.log(`📏 Size: ${getFileSizeInKB(minifiedBuild.output[0].file)} KB`); | ||
}; | ||
|
||
buildWithComponents(!!process.env.SANDBOX); |
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.
I can see some customers wanting an allow-list instead of an exclude-list.
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.
I'm mostly in agreeance with with Jon brought up.
} | ||
} | ||
}; | ||
}; |
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.
I believe that the Babel plugin was from @dompuiu, so it may have something to do with how he envisions Launch support will happen i.e. furance/forge will run Babel but not rollup.
The babel plugin in this PR is not the same as what I had in my repo: https://github.com/dompuiu/myalloy/blob/cliBuildAll/scripts/conditionalBuildBabelPlugin.mjs. The plugin from my repo is doing two things that I think it is generic enough:
While the The |
79ef5dc
to
1c5855f
Compare
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.
Just a few tiny changes, then it looks good.
package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@adobe/alloy", | |||
"version": "2.19.1", | |||
"version": "2.19.0-beta.14", |
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.
Make sure this gets updated to at least 2.19.1
@@ -15,27 +15,37 @@ governing permissions and limitations under the License. | |||
import createDataCollector from "../components/DataCollector"; | |||
import createActivityCollector from "../components/ActivityCollector"; |
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.
Make sure all OPTIONAL_COMPONENTS
, like createActivityCollector
, have a @skipwhen
comment that allows them to be excluded.
scripts/helpers/customBuild.js
Outdated
const requiredComponents = componentCreatorsContent | ||
.match(/REQUIRED_COMPONENTS = \[[\s\S]*?\]/)[0] | ||
.match(/create[A-Z]\w+/g) | ||
.map(component => component.slice(6).toLowerCase()); |
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.
What does the 6
represent? I would like to see this done in a way that doesn't have a (seemingly) random number. Same thing with the one on line 41.
…es.js during runtime
src/core/componentCreators.js
Outdated
createIdentity, | ||
createAudiences, | ||
createPersonalization, | ||
const REQUIRED_COMPONENTS = [ |
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.
Can you add a comment here that the conditional build relies on the naming of this variable so don't change it.
Changes to runFunctionalTests.jsThe Reading dist/alloy.jsThe script uses the JavaScript fs.readFile('dist/alloy.js', 'utf8', (err, data) => { // ... }); If an error occurs while reading the file, the error is logged to the console and the script returns. Checking for Included ComponentsFor each test file, the script extracts the component name from the file path and checks if JavaScript const testFiles = files.filter(file => { const componentName = file.split('/')[3]; // assuming the file path is 'test/functional/specs/{componentName}/...' return data.includes( }); If Running Functional TestsThe script runs the functional tests for the files in the JavaScript createTestCafe().then(testcafe => { const runner = testcafe.createRunner(); runner
}); AssumptionsThis script assumes a specific directory structure for the test files: 'test/functional/specs/{componentName}/...'. If your directory structure is different, you might need to adjust the way the component name is extracted from the file path. UsageYou can run this script with the following command: bash node scripts/helpers/runFunctionalTests.js This will run the functional tests for the components included in the |
…t list from skipwhen directive.
Overview
The customBuild.js feature enables users to create custom builds of the project by excluding optional components based on the @skipwhen directive in componentCreators.js. This allows for a more lightweight and tailored build process, excluding components not required for a specific deployment.
Custom Build Process
The custom build process involves analyzing the componentCreators.js file for @skipwhen directives. These directives indicate conditions under which components can be excluded from the build. For example, a component might be excluded if a certain environment variable is set to false.
Example Directive
In this example, the createPersonalization component will be excluded from the build if the ENV.alloy_personalization environment variable is set to false.
Modifying customBuild.js
To support the custom build process, modifications in customBuild.js are required to parse the @skipwhen directives and exclude components accordingly.
Key Steps:
Testing Custom Builds with runFunctionalTests.js
The runFunctionalTests.js script allows users to test custom builds by excluding tests for components not included in the build. This ensures that only relevant tests are run, aligning the testing process with the custom build.
Modifications in runFunctionalTests.js
To support testing custom builds, runFunctionalTests.js needs to be aware of which components have been excluded from the build and skip tests for those components.
Key Steps:
Example Modification
In this example, tests for the Personalization component are excluded based on the custom build configuration.
Conclusion
The customBuild.js feature, along with modifications to runFunctionalTests.js, provides a streamlined process for creating and testing custom builds. By excluding optional components and their tests, users can optimize the build and testing process for their specific needs.