<commit_before>path = require 'path'
normalizePackageData = require 'normalize-package-data'

_ = require 'underscore-plus'
async = require 'async'
CSON = require 'season'
fs = require 'fs-plus'
{Emitter, CompositeDisposable} = require 'event-kit'
Q = require 'q'
{includeDeprecatedAPIs, deprecate} = require 'grim'

ModuleCache = require './module-cache'
ScopedProperties = require './scoped-properties'

packagesCache = require('../package.json')?._atomPackages ? {}

# Loads and activates a package's main module and resources such as
# stylesheets, keymaps, grammar, editor properties, and menus.
module.exports =
class Package
  @isBundledPackagePath: (packagePath) ->
    if atom.packages.devMode
      return false unless atom.packages.resourcePath.startsWith("#{process.resourcesPath}#{path.sep}")

    @resourcePathWithTrailingSlash ?= "#{atom.packages.resourcePath}#{path.sep}"
    packagePath?.startsWith(@resourcePathWithTrailingSlash)

  @normalizeMetadata: (metadata) ->
    if typeof metadata.repository is 'string'
      normalizePackageData(metadata)
      metadata.repository.url = metadata.repository.url.replace(/^git\+/, '')

  @loadMetadata: (packagePath, ignoreErrors=false) ->
    packageName = path.basename(packagePath)
    if @isBundledPackagePath(packagePath)
      metadata = packagesCache[packageName]?.metadata
    unless metadata?
      if metadataPath = CSON.resolve(path.join(packagePath, 'package'))
        try
          metadata = CSON.readFileSync(metadataPath)
          @normalizeMetadata(metadata)
        catch error
          throw error unless ignoreErrors

    metadata ?= {}
    metadata.name = packageName

    if includeDeprecatedAPIs and metadata.stylesheetMain?
      deprecate("Use the `mainStyleSheet` key instead of `stylesheetMain` in the `package.json` of `#{packageName}`", {packageName})
      metadata.mainStyleSheet = metadata.stylesheetMain

    if includeDeprecatedAPIs and metadata.stylesheets?
      deprecate("Use the `styleSheets` key instead of `stylesheets` in the `package.json` of `#{packageName}`", {packageName})
      metadata.styleSheets = metadata.stylesheets

    metadata

  keymaps: null<commit_msg>Don't need to replace now, use module directly<commit_after>path = require 'path'
normalizePackageData = require 'normalize-package-data'

_ = require 'underscore-plus'
async = require 'async'
CSON = require 'season'
fs = require 'fs-plus'
{Emitter, CompositeDisposable} = require 'event-kit'
Q = require 'q'
{includeDeprecatedAPIs, deprecate} = require 'grim'

ModuleCache = require './module-cache'
ScopedProperties = require './scoped-properties'

packagesCache = require('../package.json')?._atomPackages ? {}

# Loads and activates a package's main module and resources such as
# stylesheets, keymaps, grammar, editor properties, and menus.
module.exports =
class Package
  @isBundledPackagePath: (packagePath) ->
    if atom.packages.devMode
      return false unless atom.packages.resourcePath.startsWith("#{process.resourcesPath}#{path.sep}")

    @resourcePathWithTrailingSlash ?= "#{atom.packages.resourcePath}#{path.sep}"
    packagePath?.startsWith(@resourcePathWithTrailingSlash)

  @loadMetadata: (packagePath, ignoreErrors=false) ->
    packageName = path.basename(packagePath)
    if @isBundledPackagePath(packagePath)
      metadata = packagesCache[packageName]?.metadata
    unless metadata?
      if metadataPath = CSON.resolve(path.join(packagePath, 'package'))
        try
          metadata = CSON.readFileSync(metadataPath)
          normalizePackageData(metadata)
        catch error
          throw error unless ignoreErrors

    metadata ?= {}
    metadata.name = packageName

    if includeDeprecatedAPIs and metadata.stylesheetMain?
      deprecate("Use the `mainStyleSheet` key instead of `stylesheetMain` in the `package.json` of `#{packageName}`", {packageName})
      metadata.mainStyleSheet = metadata.stylesheetMain

    if includeDeprecatedAPIs and metadata.stylesheets?
      deprecate("Use the `styleSheets` key instead of `stylesheets` in the `package.json` of `#{packageName}`", {packageName})
      metadata.styleSheets = metadata.stylesheets

    metadata

  keymaps: null
{'fraction_non_alphanumeric': 0.10790164717116257, 'fraction_numerical': 0.0, 'mean_word_length': 4.441558441558442, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7276362', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1174, 'n_words': 290}