How write a wrapper for, Ex: SimpleSchema?

I was trying a wrapper for, say SimpleSchema constructor on a package but it not work. What I miss?, thanks …

Package.describe({
  name: 'my:package',
  version: '0.1.0',
})

function configure(api) {
  api.versionsFrom('1.0')

  api.use([
    'aldeed:collection2@2.5.0'
  ])
}

Package.onUse(function (api) {
  configure(api)

  api.addFiles('ss.js')

  api.export('SimpleSchema')
})

Package.onTest(function (api) {
  configure(api)

  api.use('tinytest@1.0.0')
  api.use('test-helpers@1.0.0')
  api.use('my:package')

  api.addFiles('test.js')
})

the wrapper ss.js

// aldeed:simple-schema wrapper
const _SimpleSchema = SimpleSchema
SimpleSchema = function(schemas, options) {
  console.log('Not work')
  return new _SimpleSchema(simpleSchemaExtended(schemas), options)
}

test code. console.log('Not work') never reached
test.js

new SimpleSchema({})

my guest about Meteor globals on packages are wrong. How doit?

actual ss.js file:

// aldeed:simple-schema wrapper
const _SimpleSchema = SimpleSchema
SimpleSchema = class extends _SimpleSchema {
  constructor(schemas, options) {
    console.log('NOT WORK')
    super(simpleSchemaExtended(schemas), options)
  }
}

Well problem is on line:

   api.use([
    'aldeed:collection2@2.5.0'
  ])

from package.js , if I use collection2 package even before add my:package , SimpleSchema global is reset over my definition.
How can avoid this?? … right know I can´t have tinytest for my:package
and collection2 on the same package

Could you try api.use’ing https://atmospherejs.com/aldeed/simple-schema Which is the package you actually want to modify?

  api.use([
    'aldeed:simple-schema@1.3.3'
  ])

Yes it works!! and I can add collection2 package

api.use([
    'aldeed:simple-schema@1.3.3',
    'aldeed:collection2@2.5.0'
  ])

@ahref what is the different on add collection2 that ‘imply’ simple-schema vs explicity add simple-schema ?

Collection2 depends on SimpleSchema so there’s probably some weird dependancy graph going on. I’m not sure.

I just thought it might make sense to .use the package you were trying to extend.

Why are you trying to extend it btw?

Ah! ok, you got a feel!! :slight_smile: . Thanks for your sixth sense.

I need store some fields on schema with info of: relations, models, … Although this fields are SimpleSchema valid I need track then. When, for example, I merge some schemas this ‘specials’ fields should be manage differently.
Initially I have different class name like, new MetaSchema({}) but always forgot to use and at some point I have to touch attachSchema function too. Because that I extend SimpleSchema, it behave like usual do and different when found my add syntax.

EDIT: I don´t test attachSchema yet, will see …
EDIT2: Tested with attachSchema and work with extended SimpleSchema. Good!