@platformatic/generators 1.40.0 → 1.41.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -180,11 +180,13 @@ class BaseGenerator extends FileGenerator {
180
180
  const generatedConfigFile = JSON.parse(this.getFileObject('platformatic.json', '').contents)
181
181
  const fileFromDisk = await this.loadFile({ file: 'platformatic.json', path: '' })
182
182
  const currentConfigFile = JSON.parse(fileFromDisk.contents)
183
- if (generatedConfigFile.plugins && generatedConfigFile.plugins.packages) {
184
- currentConfigFile.plugins.packages = generatedConfigFile.plugins.packages
185
- } else {
186
- // remove packages because new configuration does not have them
187
- currentConfigFile.plugins.packages = []
183
+ if (currentConfigFile.plugins) {
184
+ if (generatedConfigFile.plugins && generatedConfigFile.plugins.packages) {
185
+ currentConfigFile.plugins.packages = generatedConfigFile.plugins.packages
186
+ } else {
187
+ // remove packages because new configuration does not have them
188
+ currentConfigFile.plugins.packages = []
189
+ }
188
190
  }
189
191
  this.reset()
190
192
  this.addFile({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/generators",
3
- "version": "1.40.0",
3
+ "version": "1.41.1",
4
4
  "description": "Main classes and utils for generators.",
5
5
  "main": "index.js",
6
6
  "keywords": [],
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/inquirer": "^9.0.7",
19
- "borp": "^0.13.0",
19
+ "borp": "^0.14.0",
20
20
  "c8": "^9.1.0",
21
21
  "snazzy": "^9.0.0",
22
22
  "standard": "^17.1.0",
@@ -375,7 +375,7 @@ test('should generate tsConfig file and typescript files', async (t) => {
375
375
  assert.ok(bg.getFileObject('example.test.ts', join('test', 'plugins')))
376
376
  })
377
377
 
378
- test('should throw if preapare fails', async (t) => {
378
+ test('should throw if prepare fails', async (t) => {
379
379
  const bg = new BaseGenerator({
380
380
  module: '@platformatic/service'
381
381
  })
@@ -841,6 +841,44 @@ test('on update should just touch the packages configuration', async (t) => {
841
841
  '@fastify/foo-plugin': '1.42.0'
842
842
  })
843
843
  })
844
+
845
+ test('on update should just touch the packages configuration', async (t) => {
846
+ mockNpmJsRequestForPkgs(['@fastify/foo-plugin'])
847
+ const runtimeDirectory = join(__dirname, 'fixtures', 'sample-runtime', 'services', 'no-plugin')
848
+ const dir = await moveToTmpdir(after)
849
+ await cp(runtimeDirectory, dir, { recursive: true })
850
+
851
+ const bg = new BaseGenerator({
852
+ module: '@platformatic/service',
853
+ targetDirectory: dir
854
+ })
855
+ bg.setConfig({
856
+ isUpdating: true
857
+ })
858
+ await bg.addPackage({
859
+ name: '@fastify/foo-plugin',
860
+ options: [
861
+ {
862
+ path: 'name',
863
+ type: 'string',
864
+ value: 'foobar',
865
+ name: 'FST_PLUGIN_FOO_FOOBAR'
866
+ }
867
+ ]
868
+ })
869
+ await bg.prepare()
870
+
871
+ assert.equal(bg.files.length, 1)
872
+ assert.equal(bg.files[0].file, 'platformatic.json')
873
+ assert.equal(bg.files[0].path, '')
874
+
875
+ const configFileContents = JSON.parse(bg.files[0].contents)
876
+ assert.equal(configFileContents.plugins, undefined)
877
+ assert.deepEqual(bg.config.dependencies, {
878
+ '@fastify/foo-plugin': '1.42.0'
879
+ })
880
+ })
881
+
844
882
  describe('runtime context', () => {
845
883
  test('should set config.envPrefix correctly', async (t) => {
846
884
  const bg = new BaseGenerator({
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v1.25.0/service",
3
+ "service": {
4
+ "openapi": true
5
+ },
6
+ "watch": true
7
+ }