Skip to content

Commit

Permalink
Merge pull request #3003 from FlowFuse/filter-new-modules
Browse files Browse the repository at this point in the history
Update built-in module list to include newly scoped packages
  • Loading branch information
hardillb authored Oct 26, 2023
2 parents ed8dcc4 + 550b2c6 commit 8b3d7d1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 1 addition & 3 deletions forge/db/controllers/ProjectTemplate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { BUILT_IN_MODULES } = require('../../lib/builtInModules')
const { templateFields, defaultTemplateValues, defaultTemplatePolicy } = require('../../lib/templates')
const { hash } = require('../utils')

Expand Down Expand Up @@ -89,9 +90,6 @@ module.exports = {
// ensure names and version are valid
// NOTE: `validateModuleName` and `validateModuleVersion` have frontend counterparts
// in `/frontend/src/pages/admin/Template/sections/PaletteModules.vue` and should be kept in sync
const BUILT_IN_MODULES = [
'@flowforge/nr-project-nodes'
]
const validateModuleName = (name) => !BUILT_IN_MODULES.includes(name) && /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name)
const validateModuleVersion = (version) => /^\*$|x|(?:[\^~]?(0|[1-9]\d*)\.(x$|0|[1-9]\d*)(?:\.(x$|0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)?)$/.test(version)
const moduleMap = {}
Expand Down
9 changes: 1 addition & 8 deletions forge/db/controllers/StorageSettings.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
// These are the modules we preinstall that Node-RED will report back in its
// runtime settings.
// Pre 1.0, for docker/k8s, they might have been included in the main package.json
// which means they are flagged as local - but they shouldn't be. We need to explicitly
// filter them out.
const BUILT_IN_MODULES = [
'@flowforge/nr-project-nodes'
]
const { BUILT_IN_MODULES } = require('../../lib/builtInModules')

module.exports = {
getProjectModules: async function (app, project) {
Expand Down
12 changes: 12 additions & 0 deletions forge/lib/builtInModules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// These are the modules we preinstall that Node-RED will report back in its
// runtime settings.

const BUILT_IN_MODULES = [
'@flowforge/nr-project-nodes',
'@flowfuse/nr-project-nodes',
'@flowforge/nr-file-nodes',
'@flowfuse/nr-file-nodes'
]
module.exports = {
BUILT_IN_MODULES
}
5 changes: 2 additions & 3 deletions frontend/src/pages/admin/Template/sections/PaletteModules.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
import { CheckIcon, LockClosedIcon, PencilIcon, PlusSmIcon, TrashIcon, XIcon } from '@heroicons/vue/outline'
import { BUILT_IN_MODULES } from '../../../../../../forge/lib/builtInModules.js'
import FormHeading from '../../../../components/FormHeading.vue'
import FormRow from '../../../../components/FormRow.vue'
import ChangeIndicator from '../components/ChangeIndicator.vue'
Expand Down Expand Up @@ -272,9 +274,6 @@ export default {
},
methods: {
validateModuleName (name) {
const BUILT_IN_MODULES = [
'@flowforge/nr-project-nodes'
]
return /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name) && !BUILT_IN_MODULES.includes(name)
},
validateModuleVersion (version) {
Expand Down

0 comments on commit 8b3d7d1

Please sign in to comment.