-
Notifications
You must be signed in to change notification settings - Fork 5
Support non node environment validation #24
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
24b5db5
pdcl-14485: Refactor validator into portable modules with subpath export
a2fdb64
3.0.0-beta.2
43fe0c7
pdcl-14485: due to an isDirectory() check not supported between all c…
a216969
pdcl-14485: make the directory check error more clear.
f86848b
pdcl-14485: clarifying comments about certain functions. enhance a te…
771dd30
pdcl-14485: address gathering files in node using windows broken case…
e1788af
add test case. update readme/
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /*************************************************************************************** | ||
| * (c) 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| ****************************************************************************************/ | ||
|
|
||
| // Recursively scans a directory and returns an array of relative file path strings. | ||
| // Node-only -- uses fs and path. Not suitable for browser environments. | ||
| // | ||
| // Example: for an extension layout like | ||
| // extension.json | ||
| // src/view/configuration.html | ||
| // src/view/events/click.html | ||
| // src/lib/main.js | ||
| // the returned array is e.g. | ||
| // ['extension.json', 'src/view/configuration.html', 'src/view/events/click.html', 'src/lib/main.js'] | ||
|
|
||
| 'use strict'; | ||
| var fs = require('fs'); | ||
| var pathUtil = require('path'); | ||
|
|
||
| var gatherFilesInNodeEnvironment = function(dir, root, result) { | ||
| root = root || dir; | ||
| result = result || []; | ||
| var entries = fs.readdirSync(dir); | ||
| entries.forEach(function(entry) { | ||
| var fullPath = pathUtil.join(dir, entry); | ||
| var relPath = pathUtil.relative(root, fullPath); | ||
| if (fs.statSync(fullPath).isDirectory()) { | ||
| gatherFilesInNodeEnvironment(fullPath, root, result); | ||
| } else { | ||
| result.push(relPath.replace(/\\/g, '/')); | ||
| } | ||
| }); | ||
| return result; | ||
| }; | ||
|
|
||
| module.exports = gatherFilesInNodeEnvironment; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /*************************************************************************************** | ||
| * (c) 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| ****************************************************************************************/ | ||
|
|
||
| // Validates an extension descriptor against its JSON schema and a provided file list. | ||
| // Portable -- no Node-specific APIs. Safe to use in browser environments. | ||
| // Accepts (extensionDescriptor, fileList) where fileList is an array of relative path strings. | ||
| // Returns undefined if valid, or an error string on the first problem encountered. | ||
|
|
||
| 'use strict'; | ||
| var validateSchema = require('./validateSchema'); | ||
| var validateFiles = require('./validateFiles'); | ||
|
|
||
| module.exports = function(extensionDescriptor, fileList) { | ||
| var error = validateSchema(extensionDescriptor); | ||
| if (error) return error; | ||
|
|
||
| error = validateFiles(extensionDescriptor, fileList); | ||
| if (error) return error; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /*************************************************************************************** | ||
| * (c) 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| ****************************************************************************************/ | ||
|
|
||
| // Validates that files referenced by an extension descriptor exist in a provided file list. | ||
| // Portable -- no Node-specific APIs. Safe to use in browser environments. | ||
| // Accepts (extensionDescriptor, fileList) where fileList is an array of relative path strings. | ||
| // Returns undefined if valid, or an error string if not. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| var stripQueryAndAnchor = function(path) { | ||
| return path.split('?').shift().split('#').shift(); | ||
| }; | ||
|
|
||
| var joinPath = function() { | ||
| return [].slice.call(arguments).filter(Boolean).join('/').replace(/\/+/g, '/'); | ||
|
brenthosie marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| var validateViewBasePath = function(extensionDescriptor, fileSet, fileList) { | ||
| var viewBasePath = extensionDescriptor.viewBasePath; | ||
| if (!viewBasePath) return; | ||
|
|
||
| var viewBaseNorm = viewBasePath.replace(/\/+$/, ''); | ||
| if (fileSet.has(viewBaseNorm)) { | ||
|
brenthosie marked this conversation as resolved.
|
||
| return 'The referenced viewBasePath ' + viewBasePath + ' is either not a directory or is empty.'; | ||
| } | ||
|
|
||
| var hasFileUnderPath = fileList.some(function(p) { | ||
| return p === viewBaseNorm || p.indexOf(viewBaseNorm + '/') === 0; | ||
| }); | ||
| if (!hasFileUnderPath) { | ||
| return 'The referenced viewBasePath ' + viewBasePath + ' is either not a directory or is empty.'; | ||
| } | ||
| }; | ||
|
|
||
| var validateFileList = function(extensionDescriptor, fileSet) { | ||
| var paths = []; | ||
| var platform = extensionDescriptor.platform; | ||
| var viewBase = extensionDescriptor.viewBasePath; | ||
|
|
||
| if (!platform) { | ||
| return 'the required property "platform" is missing.'; | ||
| } | ||
|
|
||
| if (extensionDescriptor.main) { | ||
| paths.push(extensionDescriptor.main); | ||
| } | ||
|
|
||
| if (extensionDescriptor.configuration) { | ||
| paths.push(joinPath(viewBase, stripQueryAndAnchor(extensionDescriptor.configuration.viewPath))); | ||
| } | ||
|
|
||
| ['events', 'conditions', 'actions', 'dataElements'].forEach(function(type) { | ||
| var features = extensionDescriptor[type]; | ||
| if (features) { | ||
| features.forEach(function(feature) { | ||
| if (feature.viewPath) { | ||
| paths.push(joinPath(viewBase, stripQueryAndAnchor(feature.viewPath))); | ||
| } | ||
| if (platform === 'web') { | ||
| paths.push(feature.libPath); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| for (var i = 0; i < paths.length; i++) { | ||
| if (!fileSet.has(paths[i])) { | ||
| return paths[i] + ' is not a file.'; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| module.exports = function(extensionDescriptor, fileList) { | ||
| var fileSet = new Set(fileList); | ||
| var error = validateViewBasePath(extensionDescriptor, fileSet, fileList); | ||
| if (error) return error; | ||
| error = validateFileList(extensionDescriptor, fileSet); | ||
| if (error) return error; | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
web-manifest.test.jsandedge-manifest.test.jsdo cover this code, but there are no direct tests verifying:Maybe consider if we need unit tests for these cases.
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 think the changes as-is don't necessitate testing these today given they weren't tested explicitly before these changes.