Skip to content

Commit dd7faac

Browse files
committed
Do not copy any theme files into project level node_modules
1 parent 23007df commit dd7faac

File tree

2 files changed

+6
-70
lines changed

2 files changed

+6
-70
lines changed

lib/launcher.js

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs/promises')
44
const { readFileSync } = require('fs')
55
const path = require('path')
66
const { log, info, debug, warn, NRlog } = require('./logging/log')
7-
const { copyDir, hasProperty } = require('./utils')
7+
const { hasProperty } = require('./utils')
88
const { States } = require('./states')
99
const { default: got } = require('got')
1010

@@ -55,7 +55,6 @@ class Launcher {
5555
credentials: path.join(this.projectDir, 'flows_cred.json'),
5656
settings: path.join(this.projectDir, 'settings.js'),
5757
userSettings: path.join(this.projectDir, 'settings.json'),
58-
themeDir: path.join(this.projectDir, 'node_modules', '@flowfuse', 'nr-theme'),
5958
npmrc: path.join(this.projectDir, '.npmrc')
6059
}
6160
}
@@ -80,11 +79,11 @@ class Launcher {
8079
packageData.dependencies['@flowfuse/nr-assistant'] = `file:${devPath}`
8180
}
8281
}
83-
if (!packageData.dependencies['@flowfuse/nr-theme']) {
84-
// Ensure the theme package is in package.json so that its resources
85-
// don't get removed by npm.
86-
packageData.dependencies['@flowfuse/nr-theme'] = '*'
87-
}
82+
// if (!packageData.dependencies['@flowfuse/nr-theme']) {
83+
// // Ensure the theme package is in package.json so that its resources
84+
// // don't get removed by npm.
85+
// packageData.dependencies['@flowfuse/nr-theme'] = '*'
86+
// }
8887
packageData.version = `0.0.0-${this.snapshot.id}`
8988
packageData.name = this.snapshot.env.FF_PROJECT_NAME
9089
if (this.snapshot.name && this.snapshot.description) {
@@ -393,26 +392,6 @@ class Launcher {
393392
}
394393
}
395394

396-
async writeThemeFiles () {
397-
info('Updating theme files')
398-
const sourceDir1 = path.join(__dirname, '..', 'node_modules', '@flowfuse', 'nr-theme')
399-
const sourceDir2 = path.join(__dirname, '..', '..', 'nr-theme')
400-
const sourceDir = existsSync(sourceDir1) ? sourceDir1 : sourceDir2
401-
const targetDir = path.join(this.projectDir, 'node_modules', '@flowfuse', 'nr-theme')
402-
try {
403-
if (!existsSync(sourceDir)) {
404-
info(`Could not write theme files. Theme not found: '${sourceDir}'`)
405-
return
406-
}
407-
if (!existsSync(targetDir)) {
408-
await fs.mkdir(targetDir, { recursive: true })
409-
}
410-
await copyDir(sourceDir, targetDir, { recursive: true })
411-
} catch (error) {
412-
info(`Could not write theme files to disk: '${targetDir}'`)
413-
}
414-
}
415-
416395
async logAuditEvent (event, body) {
417396
const data = {
418397
timestamp: Date.now(),
@@ -459,13 +438,6 @@ class Launcher {
459438
await this.writeSettings()
460439
}
461440

462-
if (!existsSync(this.files.themeDir)) {
463-
// As the theme may not present (due to earlier versions of the agent launcher),
464-
// we will independently write the theme files to the device project
465-
// (if the directory is not present)
466-
await this.writeThemeFiles()
467-
}
468-
469441
const filterEnv = (env) =>
470442
Object.entries(env).reduce((acc, [key, value]) =>
471443
key.startsWith('FORGE') ? acc : { ...acc, [key]: value }, {})

lib/utils.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
const path = require('path')
2-
const fs = require('fs').promises
31
const proxyFromEnv = require('proxy-from-env')
42

53
module.exports = {
64
compareNodeRedData,
75
compareObjects,
86
isObject,
97
hasProperty,
10-
copyDir,
118
getWSProxyAgent,
129
getHTTPProxyAgent
1310
}
@@ -85,39 +82,6 @@ function hasProperty (object, property) {
8582
return !!(object && Object.prototype.hasOwnProperty.call(object, property))
8683
}
8784

88-
/**
89-
* Copy a directory from one location to another
90-
* @param {string} src - source directory
91-
* @param {string} dest - destination directory
92-
* @param {Object} [options] - options
93-
* @param {boolean} [options.recursive=true] - whether to copy recursively (default: true)
94-
*/
95-
async function copyDir (src, dest, { recursive = true } = {}) {
96-
// for nodejs v 16.7.0 and later, fs.cp will be available
97-
if (fs.cp && typeof fs.cp === 'function') {
98-
await fs.cp(src, dest, { recursive })
99-
return
100-
}
101-
// fallback to own implementation of recursive copy (for Node.js 14)
102-
// TODO: remove this when Node.js 14 is no longer supported by the device agent
103-
const cp = async (src, dest) => {
104-
const lstat = await fs.lstat(src).catch(_err => { })
105-
if (!lstat) {
106-
// do nothing
107-
} else if (lstat.isFile()) {
108-
await fs.copyFile(src, dest)
109-
} else if (lstat.isDirectory()) {
110-
await fs.mkdir(dest).catch(_err => { })
111-
if (recursive) {
112-
for (const f of await fs.readdir(src)) {
113-
await cp(path.join(src, f), path.join(dest, f))
114-
}
115-
}
116-
}
117-
}
118-
await cp(src, dest)
119-
}
120-
12185
/**
12286
* Get a specific proxy agent for a WebSocket connection. This should be applied to the `wsOptions.agent` property
12387
*

0 commit comments

Comments
 (0)